UnicodeEncodeError:“charmap”编解码器无法对位置108110中的字符进行编码:字符映射到<undefined>

2024-03-29 15:53:01 发布

您现在位置:Python中文网/ 问答频道 /正文

我是新手。我正在学习使用python进行电子邮件分析。我想把文件转换成CSV。我使用的代码如下:

with open('mbox.csv','w') as outfile:
    writer=csv.writer(outfile)
    writer.writerow(['subject','from','to','date'])

    for message in mbox:
        writer.writerow([message['Subject'],message['from'],message['to'],message['date']])  

我不断出错:

UnicodeEncodeError: 'charmap' codec can't encode characters in position 108-110: character maps to <undefined>.

虽然看起来CSV文件是被创建的,但我还是为这个错误而烦恼。你知道吗


Tags: 文件csvto代码infrommessagedate