![](/img/trans.png)
[英]Python: reading a csv and printing to console. strange characters are being printed
[英]Strange characters in console Python
從文本文件中讀取單詞“beyoncè”,python將其作為“ beyonc \\ xc3 \\ xa9”來處理。
如果我將其寫入文件,它將正確顯示,但在控制台中將顯示如下。
另外,如果我嘗試在程序中使用它,則會得到:
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 17: ordinal not in range(128)
我怎樣才能讓Python從文本文件中讀取碧昂絲為碧昂絲並擺脫這個問題?
看看是否有幫助:
f= open('mytextfile.txt', encoding='utf-8', 'w')
f.write(line)
嘗試
string="beyonc\xc3\xa9"
string.decode("utf-8")
foo=open("foo.txt","wb")
foo.write(string)
foo.close()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.