繁体   English   中英

为什么在使用csv模块时仍然出现错误“ AttributeError:'_ io.TextIOWrapper'对象没有属性'writerows”?

[英]Why do I keep getting the error “AttributeError: '_io.TextIOWrapper' object has no attribute 'writerows” when using csv module?

我导入了CSV,文档告诉我的操作方式导致失败。

这是有问题的代码。

outfile = open("D:/stock_information/processed data/standard_deviant.csv", "w")
write_outfile = csv.writer(outfile)

for i in range(len(all_standard_deviant_info)):
    outfile.writerows(all_standard_deviant_info[i][0])
    outfile.writerows(all_standard_deviant_info[i][1])

有谁知道为什么说.writerows不存在?

您需要使用

write_outfile.writerows(all_standard_deviant_info[i][0])

因为outfile只是一个文件对象,而不是csv.writer的对象。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM