[Tutor] Running external commands from Python

Luke Paireepinart rabidpoobear at gmail.com
Sat Jun 26 03:34:40 CEST 2010


On Fri, Jun 25, 2010 at 7:48 PM, David Hutto <smokefloat at gmail.com> wrote:
> On Fri, Jun 25, 2010 at 8:16 PM, Steven D'Aprano <steve at pearwood.info> wrote:
>> On Sat, 26 Jun 2010 08:46:17 am Randy Kao wrote:
>>> Hi all,
>>>
>>> I'm a newbie to Python (switching from Perl) and had a question about
>>> the best way to run external commands in Python.
>> [...]
>>> through: os.popen, os.popen2, os.popen3, os.system,
>>> commands.getoutput()
>>
>>
>> os.system is the oldest way, and it's pretty much obsolete.
>
>
> Not to hijack  this thread, but why would accessing, what I(newbie
> ++1) know as the direct interface from python to the machine you're
> on, be obsolete? Isn't this the direct way to access your machine
> through the python 'application', if I'm using this term right?
>

He means that in most cases what you want to do is probably capture
the stdin & out.  it's not obsolete, it's just not that common of a
case. I'm not sure why he used that term.  Most people tend to use
popen because it's more useful.  However, os.popen _is_ obsolete, or
at least discouraged; the correct module to use is the subprocess
module, as I mentioned earlier.


More information about the Tutor mailing list