running programs from within python

M.N.A.Smadi smadim2 at grads.ece.mcmaster.ca
Wed Mar 9 12:22:47 EST 2005


am getting an error in the script as follows:

NameError: global name 'os' is not defined

however i dont get the same error when running from the python CLI. (and 
yes i am importing the os module)

is this a bug in python 2.3 (the one am currently using)
thanks
m.smadi

Steven Bethard wrote:

> M.N.A.Smadi wrote:
>
>> M.N.A.Smadi wrote:
>>
>>> hi;
>>> in general: how can i pass a string containing a concatenated 
>>> sequcne of command line arguments to a unix system CLI?
>>
>>
>>
>> i guess i will answer myself:
>> import os
>> os.system(string)
>
>
> Also worth noting is that if you're using Python 2.4, you might want 
> to look at the subprocess module, which replaces many of the older 
> os.* calls with a more flexible interface.  For the os.system 
> replacement, see:
>
> http://docs.python.org/lib/node235.html
>
> STeVe





More information about the Python-list mailing list