我想在python中執行一個sed命令,第一種方法直接指定文件時,可以正確輸出結果,但是第二種我打開文件操作的時候就有問題,不知道什么原因,求高手解答?
(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