Using switches with exec?

  • Thread starter =?iso-8859-1?q?Premshree=20Pillai?=
  • Start date
?

=?iso-8859-1?q?Premshree=20Pillai?=

Hello,

I need to run a Python program dynamically within
another program. I am using exec for the purpose. Is
there a way to pass parameter switches to exec?

-Premshree
[http://www.qiksearch.com/]

________________________________________________________________________
Yahoo! India Mobile: Download the latest polyphonic ringtones.
Go to http://in.mobile.yahoo.com
 
D

Diez B. Roggisch

I need to run a Python program dynamically within
another program. I am using exec for the purpose. Is
there a way to pass parameter switches to exec?

You can pass a globals-dictionary to exec, which can hold the switches
values.

Diez
 
J

Jp Calderone

Could you please elucidate with a sample script.
Suppose I need to pass the switch "-w" to the
dynamically loaded code (using eval()/exec()).
Any help is appreciated.

Options aren't typically passed to "code". They're passed to the main
function of a program. For example:

def main(argv):
o = GameOptions()
o.parse(argv[1:])
...

If your code is structured like this, you can avoid using eval() and exec
altogether and simply import and call the main function:

from foo import main
main(['progname', '-w'])

Hope this helps,

Jp
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,269
Latest member
vinaykumar_nevatia23

Latest Threads

Top