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
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.
Description. Python method popen() opens a pipe to or from command. The return value is an open file object connected to the pipe, which can be read or written depending on whether mode is 'r' (default) or 'w'. The bufsize argument has the same meaning as in open() function.
This function is intended for low-level I/O and must be applied to a file descriptor as returned by os. open() or pipe() . To close a “file object” returned by the built-in function open() or by popen() or fdopen() , use its close() method.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With