Development

NAVIGATION
CATEGORIES
REFERRENCE
LINKS
  • looking for a simple way to load a program from another pythonprogram..

    9 answers - 926 bytes - related search similar search Add To My Delicious Add To My Stumble Upon Add To My Google Mark Add To My Facebook Add To My Digg Add To My Reddit

    I was looking for a simple way to load a simple python program from
    another python program.
    I tried
    os.system(cabel)
    The file name is cabel.py a csound instrument editor
    The error I am getting is
    Traceback (most recent call last):
    File "C:\Python24\Lib\site-packages\boa-constructor\test of
    snake\Frame1.py", line 212, in CabelItems0Menu
    os.system(cabel)
    NameError: global name 'cabel' is not defined
    Localisation of messages is disabled, using default language.
    time resolution is 279.365 ns
    This is with cabel in the current directory. I have managed to use
    import to run it but it will only do it once. I may be able to use the
    exec commands but I don't want to exit the program I am using only to
    run other programs and then exit. I would also perfer that cabel is in
    it's own directory.
    thanks in advance for any help
  • No.1 | | 1565 bytes | |

    Eric_Dexter (AT) msn (DOT) com wrote:
    I was looking for a simple way to load a simple python program from
    another python program.

    I tried

    os.system(cabel)

    The file name is cabel.py a csound instrument editor

    The error I am getting is

    Traceback (most recent call last):
    File "C:\Python24\Lib\site-packages\boa-constructor\test of
    snake\Frame1.py", line 212, in CabelItems0Menu
    os.system(cabel)
    NameError: global name 'cabel' is not defined
    Localisation of messages is disabled, using default language.
    time resolution is 279.365 ns

    This is with cabel in the current directory. I have managed to use
    import to run it but it will only do it once. I may be able to use the
    exec commands but I don't want to exit the program I am using only to
    run other programs and then exit. I would also perfer that cabel is in
    it's own directory.

    thanks in advance for any help

    Read the docs: os.system() takes a string. You're calling it with an
    uninitialized variable name. Unless you have something like "cabel =
    'cabel'" somewhere before your call os.system() you can expect that
    error.

    "import cabel" will only work once because python's module import
    mechanism caches imported modules to save time when a script imports
    them more than once. To force the module to be reloaded use the reload
    function: "reload(cabel)"

    os.system() docs: #l2h-1692
    (But see the subprocess module too:
    )

    Peace,
    ~Simon
  • No.2 | | 868 bytes | |

    Hi Eric

    Check that ".py" and ".pyw" are in your PATHEXT environment variable
    (are you using Windows?). Then, if the folder that cabel is in is in
    your PATH environment variable, and the correct association for .py
    files is set up (i.e. they get run by python.exe),

    either
    os.system('cabel')
    or
    os.system('cabel.py')

    should work.

    Alternatively, you could not do any of those things, and run

    os.system('python cabel.py')

    with 'cabel.py' in the same folder as the parent script, and that
    should work too, assuming that the path to your python executable is on
    the PATH environment variable.

    If you run other commands from python quite frequently, it is probably
    a good idea to look into the "os.popen" set of commands, for more
    flexibilty.

    Caleb
  • No.3 | | 1134 bytes | |

    Caleb Hattingh wrote:
    Hi Eric

    Check that ".py" and ".pyw" are in your PATHEXT environment variable
    (are you using Windows?). Then, if the folder that cabel is in is in
    your PATH environment variable, and the correct association for .py
    files is set up (i.e. they get run by python.exe),

    either
    os.system('cabel')
    or
    os.system('cabel.py')

    should work.

    Alternatively, you could not do any of those things, and run

    os.system('python cabel.py')

    with 'cabel.py' in the same folder as the parent script, and that
    should work too, assuming that the path to your python executable is on
    the PATH environment variable.

    If you run other commands from python quite frequently, it is probably
    a good idea to look into the "os.popen" set of commands, for more
    flexibilty.

    Caleb

    import cabel and reload(cabel) seem to work fine. I am not sure why I
    am having trouble with os.system . Tells me it isn't a command.
    thanks for the help, I will look into os.popen to see what it does.
    would there be ay
  • No.4 | | 1348 bytes | |

    Caleb Hattingh wrote:
    Hi Eric

    Check that ".py" and ".pyw" are in your PATHEXT environment variable
    (are you using Windows?). Then, if the folder that cabel is in is in
    your PATH environment variable, and the correct association for .py
    files is set up (i.e. they get run by python.exe),

    either
    os.system('cabel')
    or
    os.system('cabel.py')

    should work.

    Alternatively, you could not do any of those things, and run

    os.system('python cabel.py')

    with 'cabel.py' in the same folder as the parent script, and that
    should work too, assuming that the path to your python executable is on
    the PATH environment variable.

    If you run other commands from python quite frequently, it is probably
    a good idea to look into the "os.popen" set of commands, for more
    flexibilty.

    Caleb

    import cabel and reload(cabel) seem to work fine. I am not sure why I
    am having trouble with os.system, probily something to do with the
    path. Is one better than the other when it comes to distributing
    software? Thanks for the help. Hopefully this message I get isn't
    anything important (I will have to look into os.popen later.

    Localisation of messages is disabled, using default language.
    time resolution is 279.365 ns
  • No.5 | | 744 bytes | |

    13 Aug 2006 15:17:47 -0700, "Eric_Dexter (AT) msn (DOT) com"
    <Eric_Dexter (AT) msn (DOT) comdeclaimed the following in comp.lang.python:

    import cabel and reload(cabel) seem to work fine. I am not sure why I

    If you are having to "reload(cabel)" each time you need the
    operation, you should redesign it so it becomes a callable

    import cabel

    cabel.run()

    The reload operation is really at its best when one might have
    edited the module and need to force a reread of it to make the changes
    take effect.

    os.system() and relatives (windows: os.startfile(); generic popen
    variations and subprocess) are all designed to run an external
    application, of any type, AS as external application.
  • No.6 | | 1305 bytes | |

    Eric_Dexter (AT) msn (DOT) com wrote:

    I was looking for a simple way to load a simple python program from
    another python program.

    I tried

    os.system(cabel)

    The file name is cabel.py a csound instrument editor

    The error I am getting is

    Traceback (most recent call last):
    File "C:\Python24\Lib\site-packages\boa-constructor\test of
    snake\Frame1.py", line 212, in CabelItems0Menu
    os.system(cabel)
    NameError: global name 'cabel' is not defined
    Localisation of messages is disabled, using default language.
    time resolution is 279.365 ns

    This is with cabel in the current directory. I have managed to use
    import to run it but it will only do it once. I may be able to use the
    exec commands but I don't want to exit the program I am using only to
    run other programs and then exit. I would also perfer that cabel is in
    it's own directory.

    thanks in advance for any help

    I am new to Python coding myself, but I've found that the easiest way to
    start another script from within a script, is to use the
    execfile('filename.py') command.

    There may be better ways of loading other Python scripts -- better ways that
    I'm not yet aware of -- but execfile() works for me.
  • No.7 | | 581 bytes | |

    At Sunday 13/8/2006 16:51, Eric_Dexter (AT) msn (DOT) com wrote:

    I was looking for a simple way to load a simple python program from
    >another python program.
    >
    >I tried
    >
    >os.system(cabel)
    >
    >The file name is cabel.py a csound instrument editor
    >
    >NameError: global name 'cabel' is not defined


    Have you tried os.system("cabel.py")

    Gabriel Genellina
    Softlab SRL

    P R D
    Todo lo que saber, y lo que ni imaginabas,
    en Yahoo! Respuestas (Beta).
    Probalo ya!
  • No.8 | | 824 bytes | |

    Gabriel Genellina wrote:
    At Sunday 13/8/2006 16:51, Eric_Dexter (AT) msn (DOT) com wrote:

    I was looking for a simple way to load a simple python program from
    >another python program.
    >
    >I tried
    >
    >os.system(cabel)
    >
    >The file name is cabel.py a csound instrument editor
    >
    >NameError: global name 'cabel' is not defined
    >

    Have you tried os.system("cabel.py")

    That did not seem to work, os.startfile worked great. I haven't tried
    passing commands to csound with it yet but maybe os.sytem will work
    better with that than it did python since I got the idea to use that to
    pass arguments to them from a csound example. won't have time until
    this weekend to try that though, or the exec(file)
  • No.9 | | 760 bytes | |

    14 Aug 2006 17:25:39 -0700, "Eric_Dexter (AT) msn (DOT) com"
    <Eric_Dexter (AT) msn (DOT) comdeclaimed the following in comp.lang.python:

    That did not seem to work, os.startfile worked great. I haven't tried

    That would tend to imply that "Windows" knows how run ".py"
    (startfile is the equivalent of double-clicking an icon), but the
    command interpreter is not configured with .py as an extension for
    executable programs.

    a command shell (if you've not created a short-cut for such, it
    is at: prompt

    Type: echo %PATHEXT%

    C:\Documents and Settings\Dennis Lee Bieber>echo %PATHEXT%
    CM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.py w;.py;.pyo;.pyc;.tcl

    Is .py in the list yours shows?

Re: looking for a simple way to load a program from another pythonprogram..


max 4000 letters.
Your nickname that display:
In order to stop the spam: 7 + 6 =
QUESTION ON "Development"

EMSDN.COM