遇到一個奇怪的 Error, 在 MacOS 裡執不會出問題,但在 Linux 裡執行會有下列的Error:
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe6 in position 3360: ordinal not in range(128)
我的 source code:
with open(csv_filepath) as csvfile: rows = csv.reader(csvfile) for row in rows: ....
解法:
with open(csv_filepath, encoding="utf-8") as csvfile:
rows = csv.reader(csvfile)
for row in rows:
....
附註:由於 python 2 會在 2020 就停止支援,所以上面 code 是 python 3.