[Tutor] How to pass a python variable to subprocess.call?

Sean Carolan scarolan at gmail.com
Tue Oct 26 00:01:34 CEST 2010


I'm rewriting a bunch of my bash scripts to get some python practice.
There are some instances where python doesn't have the built-in text
processing that I need, so I'm using subprocess.call.  How can I pass
a python variable to these subprocesses?  For example:

mydir = "/usr/local/bin"
subprocess.call("ls -l /usr/local/bin", shell=True)

How do I replace /usr/local/bin in the subprocess call with the mydir variable?


More information about the Tutor mailing list