我已经编写了该程序,但它显然不起作用。我的意思是代码的最后一部分。该程序正在创建文件并向 csv 文件添加一些内容。代码的最后一部分应该向已经存在的文件添加更多数据,但是每次我想运行这个程序时,我都会遇到这种错误:Traceback (most recent call last): File "/Users/grzegorzspytek/Desktop/Sending_automated_mails/nw_csv.py", line 121, in <module> for row in reader: File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/csv.py", line 111, in __next__ self.fieldnames File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/csv.py", line 98, in fieldnames self._fieldnames = next(self.reader)_csv.Error: iterator should return strings, not bytes (did you open the file in text mode?)之后,我将“开放模式”从“rb”改为“r+”Traceback (most recent call last): File "/Users/grzegorzspytek/Desktop/Sending_automated_mails/nw_csv.py", line 125, in <module> "Email": row["Email"] File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/csv.py", line 155, in writerow return self.writer.writerow(self._dict_to_list(rowdict)) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/tempfile.py", line 481, in func_wrapper return func(*args, **kwargs)TypeError: a bytes-like object is required, not 'str' 看起来我被要求把它改回来,但每次我这样做时,错误都会交替出现。有什么解决办法吗?
添加回答
举报
0/150
提交
取消