pythonbackticks

Equivalent of Bash Backticks in Python


What is the equivalent of the backticks found in Ruby and Perl in Python? That is, in Ruby I can do this:

foo = `cat /tmp/baz`

What does the equivalent statement look like in Python? I've tried os.system("cat /tmp/baz") but that puts the result to standard out and returns to me the error code of that operation.


Solution

  • output = os.popen('cat /tmp/baz').read()