[Tutor] passing variables to the system command

Alan Gauld alan.gauld at blueyonder.co.uk
Fri Aug 6 08:21:54 CEST 2004

> I'm having problems finding a way to pass variables when using the
> command in python.

> argument1 = filename1
> argument2 = filename2
> os.system("some_other_python_script.py argument1 argument2")


os.system("some_other_python_script.py %s %s" % (argument1,

In other words insert the values using the string format operator.

Also you might be safer calling python explicitly:

command ="python some_python_script.py %s %s" % (argument1, argument2)

> os.system("chmod u+x argument1")

The problem with this approach is that the external environment
that system() creates has no idea what argument1 means - it only
exists inside your program. You have to translate argument1 back
into a literal value before calling system()


Alan G
Author of the Learn to Program web tutor

More information about the Tutor mailing list