我想在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