Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > looking for a simple way to load a program from another python program..

Reply
Thread Tools

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

 
 
Eric_Dexter@msn.com
Guest
Posts: n/a
 
      08-13-2006
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

 
Reply With Quote
 
 
 
 
Simon Forman
Guest
Posts: n/a
 
      08-13-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) 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

 
Reply With Quote
 
 
 
 
Caleb Hattingh
Guest
Posts: n/a
 
      08-13-2006
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

 
Reply With Quote
 
Eric_Dexter@msn.com
Guest
Posts: n/a
 
      08-13-2006

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

 
Reply With Quote
 
Eric_Dexter@msn.com
Guest
Posts: n/a
 
      08-13-2006

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

 
Reply With Quote
 
=?iso-8859-1?q?Luis_M._Gonz=E1lez?=
Guest
Posts: n/a
 
      08-13-2006
Try this:

import os
os.startfile('cabel.py')

This should work with any program or file, not only python ones.

Hope this helps,
Luis

 
Reply With Quote
 
Dennis Lee Bieber
Guest
Posts: n/a
 
      08-14-2006
On 13 Aug 2006 15:17:47 -0700, "(E-Mail Removed)"
<(E-Mail Removed)> declaimed 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.
--
Wulfraed Dennis Lee Bieber KD6MOG
(E-Mail Removed) (E-Mail Removed)
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: (E-Mail Removed))
HTTP://www.bestiaria.com/
 
Reply With Quote
 
AlbaClause
Guest
Posts: n/a
 
      08-14-2006
(E-Mail Removed) 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


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.


--
--
There are several things that I will never be:
* I will never be attracted to females.
* I will never enjoy the company of others.
Exactly how these realities bode for my enemy, is not of my concern.

 
Reply With Quote
 
Gabriel Genellina
Guest
Posts: n/a
 
      08-14-2006
At Sunday 13/8/2006 16:51, (E-Mail Removed) 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





__________________________________________________
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya!
http://www.yahoo.com.ar/respuestas

 
Reply With Quote
 
Eric_Dexter@msn.com
Guest
Posts: n/a
 
      08-15-2006

Gabriel Genellina wrote:
> At Sunday 13/8/2006 16:51, (E-Mail Removed) 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)..



http://www.stormpages.com/edexter/csound.html

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[ANN] require_all 1.0.0: A wonderfully simple way to load your code Tony Arcieri Ruby 11 07-15-2009 08:09 PM
Looking for a way to include Pyhtho scripting INSIDE a python program John Antypas Python 5 04-13-2008 05:43 PM
How to get inputs for a python program that run from another python program pradeep nair Python 2 06-12-2007 01:20 PM
How to force a load of one control from another control on another form? et ASP .Net 1 06-29-2005 07:45 PM
How to force a load of one control from another control on another form? et ASP .Net Datagrid Control 0 06-29-2005 06:05 PM



Advertisments