Running Win XP application programs.or Python .py file from script

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pycircle
    New Member
    • Sep 2006
    • 2

    #1

    Running Win XP application programs.or Python .py file from script

    From a python module, I want to run any.py module, to open it in the shell, just like if I were in IDLE editor and selecting EDIT / Run Module.

    I have tried a lot of things, including importing a python.py file
    such as, CooperPairs.py, which only has print statements.
    This module is not a function, and should not be compiled.

    import CooperPairs
    ( Runs one time).

    Also, I have used import os to start Windows applications.

    import os
    os.startfile(r' C:\Bk2CDNFS\Tes t.xls')

    When I try this for Python modules, I get this error,

    "Not a valid Win32 application"
  • pycircle
    New Member
    • Sep 2006
    • 2

    #2
    I found a partial answer from the built-in function,
    execfile('Coope rPair.py', globals() )

    This does execute in a new shell, which behaviour I do want sometimes,

    but my shell is already open when I respond to an input prompt, and I want the file to execute in this same shell, so that all variables will still be defined.

    Originally posted by pycircle
    From a python module, I want to run any.py module, to open it in the shell, just like if I were in IDLE editor and selecting EDIT / Run Module.

    I have tried a lot of things, including importing a python.py file
    such as, CooperPairs.py, which only has print statements.
    This module is not a function, and should not be compiled.

    import CooperPairs
    ( Runs one time).

    Also, I have used import os to start Windows applications.

    import os
    os.startfile(r' C:\Bk2CDNFS\Tes t.xls')

    When I try this for Python modules, I get this error,

    "Not a valid Win32 application"

    Comment

    • bartonc
      Recognized Expert Expert
      • Sep 2006
      • 6478

      #3
      1) The best way to re-run code is to start thinking about "scripts" as modules of your program. Then in your module define a function like this:

      In MyModule.py you would write:

      def MyFunc():
      [put the code that is in the "script" here]

      Then you can either:

      import MyModule
      MyModule.MyFunc ()

      or:

      from MyModule import *
      MyFunc()

      2) I can't reproduce the error message that you are getting from os.startfile().

      What version of Python are you running? Does Python (command line) show up in your Start menu?

      Originally posted by pycircle
      From a python module, I want to run any.py module, to open it in the shell, just like if I were in IDLE editor and selecting EDIT / Run Module.

      I have tried a lot of things, including importing a python.py file
      such as, CooperPairs.py, which only has print statements.
      This module is not a function, and should not be compiled.

      import CooperPairs
      ( Runs one time).

      Also, I have used import os to start Windows applications.

      import os
      os.startfile(r' C:\Bk2CDNFS\Tes t.xls')

      When I try this for Python modules, I get this error,

      "Not a valid Win32 application"

      Comment

      Working...