import subprocess
logfile = open('/dev/log', 'w')
output, error = subprocess.Popen(['ls'], stdout=subprocess.PIPE, stderr=
    subprocess.PIPE).communicate()
logfile.write(output)
logfile.close()
In Python, what is the best way to execute a local Linux command stored in a string?