473,320 Members | 1,713 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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

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

Aug 13 '06 #1
8 2274
Er*********@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

Aug 13 '06 #2
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

Aug 13 '06 #3

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

Aug 13 '06 #4

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

Aug 13 '06 #5
Try this:

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

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

Hope this helps,
Luis

Aug 13 '06 #6
Er*********@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
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.

Aug 14 '06 #7
At Sunday 13/8/2006 16:51, Er*********@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..

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

Aug 14 '06 #8

Gabriel Genellina wrote:
At Sunday 13/8/2006 16:51, Er*********@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..

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

Aug 15 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Chris Gray | last post by:
Is there such a beast? In particular, I'm looking for a production-quality proxy server fully compliant with HTTP/1.1 written in Python. If there isn't, is there anything that comes close? ...
4
by: Paul Miller | last post by:
Some background first - we have some software that embeds a Python interpreter into a host application. Scripts are loaded dynamically and used. But we want to support the ability to edit scripts...
22
by: Martin MOKREJ© | last post by:
Hi, I'm looking for some easy way to do something like include in c or PHP. Imagine I would like to have: cat somefile.py a = 222 b = 111 c = 9
5
by: max(01)* | last post by:
hello. i wrote a very simple tkinter demo program that uses menus, buttons, labels, entries, frames and secondary toplevels. it is a python version of a java program made by a colleague. ...
11
by: JKop | last post by:
Take the following simple function: unsigned long Plus5Percent(unsigned long input) { return ( input + input / 20 ); } Do yous ever consider the possibly more efficent:
6
by: Jack | last post by:
Basically I am trying to find a high performance web server. Since Python is installed on all of the servers, It'll be great if the web server is written in Python as well. Otherwise, I will have...
4
by: John Henry | last post by:
I am looking for a ready made simple graph package. I found an extensive one in the piana package but when I try to use just the graph portion, it fails to load because of the line: class...
10
true911m
by: true911m | last post by:
This is a simple walkthrough to get PyInstaller up and running. I decided to give PI a try, because it claims to be more selective about what it bundles into its executable files by default, and...
18
by: W. Watson | last post by:
See Subject. It's a simple txt file, each line is a Python stmt, but I need up to four digits added to each line with a space between the number field and the text. Perhaps someone has already done...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.