467,188 Members | 1,419 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,188 developers. It's quick & easy.

Executing a python script with arguments from a python script

Hi,

I need to call a python script, with command line arguments (it is an
autonomous script with a __main__), from within another python script.
Can I use exec() or execfile() for this? How to pass the arguments?

Thanks,

Olivier.

Dec 12 '05 #1
  • viewed: 3162
Share:
3 Replies
ol****@gmail.com wrote:
Hi,

I need to call a python script, with command line arguments (it is an
autonomous script with a __main__), from within another python script.
Can I use exec() or execfile() for this? How to pass the arguments?

Thanks,

Olivier.


Obligatory "ugh."

Are you sure you want to do that? Just make the part you want to execute into a
function and then import it as a module. You will thank me later.

To reluctantly answer your question: see os.system.

But don't see os.system. Use python like python.

James
Dec 12 '05 #2
You can pass arguments into a python script, see getopt module.
Then to call an external script you would use subsystem module
(or os.system if you are on earlier version of python).

If you can, just make the other python program into a
function and import it as James Stroud suggests in a separate
post.
ol****@gmail.com wrote:
Hi,

I need to call a python script, with command line arguments (it is an
autonomous script with a __main__), from within another python script.
Can I use exec() or execfile() for this? How to pass the arguments?

Thanks,

Olivier.

Dec 13 '05 #3
Larry Bates wrote:
You can pass arguments into a python script, see getopt module.
Then to call an external script you would use subsystem module
(or os.system if you are on earlier version of python).


I think getopt is a little dated. Try optparse. To quote the python
documentation, it is a "More powerful command line option parser".

http://docs.python.org/lib/module-optparse.html

James
Dec 13 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Tubby Tudor | last post: by
699 posts views Thread by mike420@ziplip.com | last post: by
reply views Thread by Kurt B. Kaiser | last post: by
13 posts views Thread by Darren Dale | last post: by
reply views Thread by Nick Coghlan | last post: by
15 posts views Thread by Nick Coghlan | last post: by
8 posts views Thread by John Salerno | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.