0

经过一些地理定位工作后,我正在使用 DictWriter 将字典写入 csv。

location = geolocator.reverse(coords)
row["address"] = location.address
writer.writerow(row)

这会产生:

File "C:\bin64\python\3.4.3\lib\encodings\cp1252.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\u200e' in
    position 118: character maps to <undefined>
4

1 回答 1

1

我的问题在于我如何打开文件。我想我应该在问题中发布。我需要在打开文件时设置编码。

with open('results.csv', mode='w', encoding='utf-8', newline='') as file:
    ...
于 2015-07-02T15:36:41.260 回答