python os.popen.readlines异常_python中执行sed命令操作源文件时出现错误
我想在python中執(zhí)行一個(gè)sed命令,第一種方法直接指定文件時(shí),可以正確輸出結(jié)果,但是第二種我打開(kāi)文件操作的時(shí)候就有問(wèn)題,不知道什么原因,求高手解答?(1)>>>sedcmd="sed-n\'s/{/...
我想在python中執(zhí)行一個(gè)sed命令,第一種方法直接指定文件時(shí),可以正確輸出結(jié)果,但是第二種我打開(kāi)文件操作的時(shí)候就有問(wèn)題,不知道什么原因,求高手解答?
(1)
>>> sedcmd="sed -n \'s/{//g; p\' /qye/python/mytestpython/tmp.txt"
>>> a=os.popen(sedcmd)
>>> a.readlines()
["'copy_reg': , 'encodings': , 'site': , '__builtin__...module 'exceptions'(built-in)>, 'abrt_exception_handler': , 'os':}\n", '\n']
>>>
(2)
>>> withopen("/qye/python/mytestpython/tmp.txt") as srcfile:
... sedcmd="sed -n \'s/{//g;p\' srcfile"
... a=os.popen(sedcmd)
...
>>> sed: can't read srcfile: No such file ordirectory
展開(kāi)
總結(jié)
以上是生活随笔為你收集整理的python os.popen.readlines异常_python中执行sed命令操作源文件时出现错误的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: python中f点flush是什么函数_
- 下一篇: typedef struct 先声明后定