Perl-like backtick in Python

Noah noah at noah.org
Thu May 2 15:54:29 EDT 2002


If you want to control NONINTERACTIVE applications like cat or ls
then try this:

	str = os.popen('cat myfile.in').read()

You can't do this very well with interactive applications like telnet,
but then the Perl backticks don't do that either.

Python has backticks too, but it returns repr() on the
enclosed expression or object.

Noah

-----Original Message-----
From: python-list-admin at python.org
[mailto:python-list-admin at python.org]On Behalf Of Tom Verbeure
Sent: Thursday, May 02, 2002 11:48 AM
To: python-list at python.org
Subject: Perl-like backtick in Python


Hi All,

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?

Thanks,
Tom






More information about the Python-list mailing list