가능한 중복 :
Setting the correct encoding when piping stdout in python리디렉션이 파이썬 스크립트에서 작동하지 않는 이유는 무엇입니까?
for i in range(999):
print i, unichr(i)
파일에 저장 예상대로 파이썬 쉘 (2.7.3)의 다음 실행 (asd.py), 쉘에서 실행 중임
$ ./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)
이 왜입니까? 어떻게 해결할 수 있을까요?
http://stackoverflow.com/questions/492483/setting-the-correct-encoding-when-piping-stdout-in-python –
sr2222 @ 살펴 보자 : 그 대답을, 덕분에 – user1358