联机documentation声明现在不推荐使用os.popen。所有其他已弃用的函数都会适时发出弃用警告。例如:
>>> 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]
另一方面,函数os.popen会自动完成:
>>>len(list(os.popen('ps h -eo pid:1,command')))
202
没有任何警告。三种可能的情况
哪一个是正确的?
有关背景信息,下面是我正在使用的Python:
>>> 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)]
os.popen的参数取自堆栈溢出时的reply of mine。
附录:多亏了cobbalbelow,在Python 3.1中,os.popen并没有被弃用。
这是PEP。
我能想到的一件事是,os.popen存在于python3中,而os.popen2则不存在。因此,其中一个比另一个“更不推荐”,并计划更快地从语言中删除。
与此同时,我打开了一个关于Python问题跟踪程序的ticket。我会一直问这个问题,直到票关闭为止。
相关问题 更多 >
编程相关推荐