7

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.

Community
  • 1
  • 1
krawyoti
  • 19,695
  • 1
  • 23
  • 17
  • 1
    What does it matter? Why do you need to know the "correct" reason? It's claimed as deprecated and subprocess.Popen is the replacement. What more do you need to know? How does it improve your code to know it? – S.Lott Jul 08 '09 at 14:03
  • 1
    I guess that actually lots and lots of code depend on this function. – liori Jul 08 '09 at 14:03
  • 3
    Dear S.Lott, I know that it is not always easy for a non-native English speaker to be always perfectly clear, and so I apologize if what I write is not easily understandable. But could you please, pretty please, at least make an effort at reading my question? I'm not asking what's the reason. I'm asking who or what's wrong: the docs, the released Python code, or myself in expecting that both are consistent. – krawyoti Jul 08 '09 at 14:36
  • @krawyoti: You asked "which one is the correct one?" Why does it matter which reason is the correct reason? How does knowing which is the correct one help? How does knowing which reason is the correct reason help you fix a programming problem? – S.Lott Jul 08 '09 at 14:42
  • 2
    Dear S. Lott, let me try a different approach. Why do you say that os.popen is deprecated? I could claim that the docs are wrong. Only popen2, popen3, etc. are in fact deprecated, whereas os.popen, which is directly lifted from posix.popen is not. Please compare line 44 with line 669 in http://svn.python.org/view/python/tags/r262/Lib/os.py – krawyoti Jul 08 '09 at 15:06
  • @krawyoti: Please update your question to clarify it. Don't add comments. Fix the question. And please explain what programming problem you are having. I don't see any of your code that's broken or not working. – S.Lott Jul 08 '09 at 15:16
  • 3
    Dear S.Lott, according to the FAQ, questions do not have to revolve around broken or non-working code. If you don't see why it is important for the maintainability of a piece of software whether a function is deprecated, I think the appropriate action is for you to pose a separate question, to which I'd be delighted to contribute an answer. – krawyoti Jul 08 '09 at 17:22
  • @krawyoti. If you question has something to do with maintainability *after* deprecation, then please update your question to say this. Please update your question. Please indicate why "which one is the correct one?" has something to do with maintainability. I cannot understand the question as asked. – S.Lott Jul 08 '09 at 17:50
  • 1
    I lol'd at the conversation in these comments. – Ryan Haining Jul 26 '13 at 22:11

4 Answers4

5

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
  • 5,394
  • 3
  • 32
  • 38
4

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
  • 69,903
  • 20
  • 143
  • 156
  • 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 Jul 08 '09 at 15:47
3

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
  • 19,695
  • 1
  • 23
  • 17
  • Congratulations on asking such a perceptive question and helping push this discrepancy towards closure via formal channels. So far it looks like popen will stay around, and get documentation. Yay! – nealmcb May 07 '11 at 02:02
0

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

Purrell
  • 12,461
  • 16
  • 58
  • 70