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)。 –