python - 为什么我在使用 csv 模块时不断收到错误 "AttributeError: ' _io.TextIOWrapper' object has no attribute 'writerows"?

标签 python csv

我导入的是 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 的对象。

关于python - 为什么我在使用 csv 模块时不断收到错误 "AttributeError: ' _io.TextIOWrapper' object has no attribute 'writerows"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28401342/

相关文章:

Python 将文本写入两列的 CSV

python - 使用python将日期时间转换为mysql格式

php - 我如何提示用户下载 PHP 生成的 .CSV 文件,我应该如何处理删除它?

python - Python 中的多范围产品

python - AttributeError : partially initialized module 'turtle' has no attribute 'Turtle' (most likely due to a circular import)

python - 如何在 Ubuntu 11.10 中使用 Python 2.6?

javascript - NodeJS下载csv文件到缓冲区

django - 在 ModelForm 的 Charfield 中显示以逗号分隔的 ManyToMany 项目列表

返回多个列表的 Python 列表理解

python - 为道路修建十字路口时出错