views:

1425

answers:

4

The on-line documentation states that os.popen is now deprecated. All other deprecated functions duly raise a DeprecationWarning. For instance:

>>> import os
>>> [c.close() for c in os.popen2('ps h -eo pid:1,command')]
__main__:1: DeprecationWarning: os.popen2 is deprecated.  Use the subprocess module.
[None, None]

The function os.popen, on the other hand, completes silently:

>>>len(list(os.popen('ps h -eo pid:1,command')))
202

Without raising a warning. Of the three possible scenarios

  1. It is expected behaviour that documentation and standard library have different ideas of what is deprecated;
  2. There is an error in the documentation and os.popen is not really deprecated;
  3. There is an error in the standard library and os.popen should raise a warning;

which one is the correct one?

For background information, here's the Python I'm using:

>>> import sys
>>> print sys.version
2.6.2 (r262:71600, May 12 2009, 10:57:01) 
[GCC 4.2.4 (Ubuntu 4.2.4-1ubuntu3)]

The argument to os.popen is taken from a reply of mine here on Stack Overflow.

Addendum: Thanks to cobbal below, it turns out that os.popen is not deprecated in Python 3.1, after all.

+3  A: 

one thing that I can think of is that os.popen exists in python3, while os.popen2 doesn't. So one is "more deprecated" than the other, and scheduled for sooner removal from the language.

cobbal
That's interesting: not only os.popen is still there in Python 3.1 but it's not even deprecated. See http://docs.python.org/3.1/library/os.html
krawyoti
+2  A: 

Here is the PEP.

Deprecated modules and functions in the standard library:

    - buildtools
    - cfmfile
    - commands.getstatus()
    - macostools.touched()
    - md5
    - MimeWriter
    - mimify
    - popen2, os.popen[234]()
    - posixfile
    - sets
    - sha
kjfletch
A: 

In the meanwhile I have opened a ticket on the Python issue tracker. I'll keep this question open until the ticket is closed.

krawyoti
A: 

commands.getstatusoutput still uses it according to the 2.6.4 documentation.

perrierism
commands is Unix specific module.
Sorin Sbarnea