Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Equivalent of Bash Backticks in Python [duplicate]

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.

like image 829
Chris Bunch Avatar asked Sep 11 '09 13:09

Chris Bunch


Video Answer


1 Answers

output = os.popen('cat /tmp/baz').read() 
like image 154
John Kugelman Avatar answered Sep 20 '22 13:09

John Kugelman