【发布时间】:2012-12-12 11:15:10
【问题描述】:
可能重复:
Setting the correct encoding when piping stdout in python
以下内容按预期在 python shell (2.7.3) 中运行
for i in range(999):
print i, unichr(i)
将其保存在文件 (asd.py) 中,并在 shell 中运行
$ ./asd.py
也可以,但是
$ ./asd.py > asd.txt
给予:
Traceback (most recent call last):
File "./asd.py", line 3, in <module>
print i, unichr(i)
UnicodeEncodeError: 'ascii' codec can't encode character u'\x80' in position 0: ordinal not in range(128)
这是为什么呢?如何解决?
【问题讨论】:
-
@sr2222: 回答了,谢谢
标签: python bash shell redirect