0
我有两个脚本:这些os.popen调用有什么区别?
的首部作品好:
import os
os.popen(‘grep abc filename’)
第二不起作用:
import os
os.popen(‘grep abc’ + ’filename’)
但这:
os.popen(‘grep abc filename’ + ‘>’ + ‘filename2’)
所以,我无法理解差异。第二个版本有什么问题?
在第二个命令中'abc'和'filename'之间没有空格。 –
我假设你正在运行Python 2.你应该使用['subprocess'](https://docs.python.org/2/library/subprocess.html)(或者如果你在POSIX操作系统上是'subprocess32') ,'os.popen'是[弃用](https://docs.python.org/2/library/os.html?highlight=os.popen#os.popen)。 –