2017-04-14 70 views
-1

我正在寫一個程序來計算python(3.6)的單詞,代碼從終端平穩運行。但是如果我使用python IDLE,會發生下面的錯誤:關於UnicodeDecodeError

Traceback (most recent call last): 
File "/Users/zhangchaont/python/Course Python Programming/6.7V2.py", line 122, in <module> 
    main() 
File "/Users/zhangchaont/python/Course Python Programming/6.7V2.py", line 21, in main 
    for line in txtFile: 
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/encodings/ascii.py", line 26, in decode 
    return codecs.ascii_decode(input, self.errors)[0] 
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe3 in position 33: ordinal not in range(128) 

如何解決這個問題?

+2

請參閱代碼片段 – brennan

回答

0

由於沒有太多有關您的代碼的信息。我只能建議,而不是編解碼器,你也可以使用這個軟件包。 https://github.com/iki/unidecode。下面的方法應該可以解決你的問題。用open方法打開文件,並將其傳遞給file_handle.read()

unidecode.unidecode_expect_nonascii(string)