我正在從web服務獲取純文本到對象p
,我想用Python將它存儲在.txt
文件中。在Python中編寫文本文件時從Unicode轉換爲ASCII的錯誤
我做這樣的事情:
with open("output","w") as t2:
t2.write(p.content)
但下面的編碼問題出現了:
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe8' in position 10: ordinal not in range(128)
我在Ubuntu和PycharmIDE。我怎樣才能克服這個問題?
https://stackoverflow.com/questions/6048085/python-write-unicode-text-to-a-文本文件 – KarlC
文檔參考:[Unicode指南](https://docs.python.org/3.5/howto/unicode.html) – dsh