The problem are the double quotes inside your double-quoted string. You probably wanted to write something like:
os.system("""script.py 'arg1 "mydir_%d" arg2 '""" % i)
Or, escaping the double quotes:
os.system("script.py 'arg1 \"mydir_%d\" arg2 '" % i)
Even though the double quotes are actually useless in this circumstance...
I don't really know why you are adding the single quotes inside that command. The single-quote delimited string would be considered a single argument. In the example script.py
will receive one argument of the form arg1 "my_dir_N" arg2
where N
is an integer. If you want to pass more than one argument to the program don't group them with single quotes.
Also you should avoid os.system
altogether. The subprocess
module provides a much safer and more flexible interface.
The code using subprocess
would be:
import subprocess
for i in listofdirnumbers:
subprocess.call(['script.py', 'arg1', 'my_dir_%d' % i, 'arg2'])
(this will provide three arguments to script.py
).