【发布时间】:2012-11-28 21:55:47
【问题描述】:
我正在使用subprocess 运行命令(来自衍生的守护程序)并尝试将结果写入文件。来自Popen 的结果字符串是bytestring。在写入文件之前,如何将其格式化为人类可读的内容?使用python3.2
试过了:
print (x,file=o)
f.write(str(rc.so))
print (str(rc.so) + "\n")
没有任何东西最终看起来可读..
可疑代码:
rc = subprocess.Popen([cmd], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
x = rc.stdout.readlines()
rc.so, rc.se = rc.communicate()
with open(of,'w') as o, open(ef,'w') as e:
print (str(rc.so) + "\n",file=o)
【问题讨论】:
-
你试过解码吗?
your_string.decode('utf-8')?
标签: python python-3.2