1 Reply Latest reply on Nov 9, 2015 2:26 PM by CMata_Intel

    python import error:-

    falak.desai@yahoo.com

      Hello everyone,

       

      I'm trying to run a program which uses keyboard event.

      basically i want to run specific bash script when I press a particular key.

       

       

      my python program name is  "command.py"

      when I press "F" key then first bash script "first.sh"  should run.

      when I press "S" key then second bash script "second.sh"  should run.


      but it returns an error:


      ImportError: No module named msvcrt


      msvcrt is for windows and not for python so now what should i do to take keyboard key pressed ??



      my program is like below:

      ____________________________________________________________________________________________________________

      #!/usr/bin/python

       

      import threading

      import msvcrt

      import subprocess

       

      class myThread (threading.Thread):

          def __init__(self, name):

              threading.Thread.__init__(self)       

              self.name = name

       

          def run(self):

              process(self.name)

       

      def process(threadname):

       

         identity=threadname

       

         if(identity=="first"):

        # if second.sh is running, then kill second.sh & start first.sh

        killall second.sh

        subprocess.call("first.sh")

       

         elif(identity=="operation"):

        # if first.sh is running, then kill second.sh & start first.sh

        killall first.sh

        subprocess.call("second.sh")

       

      # Create new threads

      thread1 = myThread("first")

      thread2 = myThread("second")

       

      # Start new Threads

      thread1.start()

      thread2.start()

      ____________________________________________________________________________________________________________