Perl-like backtick in Python

Erik Max Francis max at alcyone.com
Thu May 2 14:56:51 EDT 2002


Tom Verbeure wrote:

> In Perl i can do something like this:
> 
> $str = `cat myfile.in`;
> 
> Basically the string that is surrounded by the backticks is executed
> by a shell and the stdout is returned as a string.
> 
> In the python library, there is spawn*, exec* and system, but the
> return the exit status of the command, not the output. Any suggestions
> about who to do this?

You want os.popen, or one of the related beasts in the popen2 module.

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE
/  \ Life is one long process of getting tired.
\__/ Samuel Butler
    Interstelen / http://www.interstelen.com/
 A multiplayer, strategic, turn-based Web game on an interstellar scale.



More information about the Python-list mailing list