472,145 Members | 1,391 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

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
3 3344
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 | 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
reply views Thread by Saiars | last post: by

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.