Executing a python script with arguments from a python script

O

olaufr

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.
 
J

James Stroud

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
 
L

Larry Bates

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.
 

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

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top