我上無法打開文件,任何性格特徵的中國,與encording設置爲utf-8
提高UnicodeEncodeError:編碼= 'UTF-8' 打開時,utf-8的文件,中國焦炭
text = open('file.txt', mode='r', encoding='utf-8').read()
print(text)
UnicodeEncodeError: 'charmap' codec can't encode character '\u70e6' in position 0: character maps to <undefined>
該文件是100%utf-8。
http://asdfasd.net/423/file.txt
http://asdfasd.net/423/test.py
如果我刪除encoding='utf-8'
一切正常。
這裏編碼有什麼問題?
打開文件時我總是用encoding='utf-8'
,我現在不用現在發生什麼了。
您在閱讀文件時沒有問題,但使用*寫*(或打印)。讀取會導致一個'UnicodeDecodeError',但是你有一個* encoding *的問題。 –
見http://wiki.python.org/moin/PrintFails –