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

Simon Forman rogue_pedro at yahoo.com
Sun Aug 13 16:46:25 EDT 2006


Eric_Dexter at msn.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 OnCabelItems0Menu
>     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
>
> http://www.stormpages.com/edexter/csound.html

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: http://docs.python.org/lib/os-process.html#l2h-1692
(But see the subprocess module too:
http://docs.python.org/lib/module-subprocess.html)

Peace,
~Simon




More information about the Python-list mailing list