Python AttributeError: 'module' 对象没有属性 'reader'
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35341363/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
AttributeError: 'module' object has no attribute 'reader'
提问by Tom Lowbridge
I get the error:
我收到错误:
AttributeError: 'module' object has no attribute 'reader')
AttributeError: 'module' 对象没有属性 'reader')
when I run the code below but I can't see why?
当我运行下面的代码但我不明白为什么?
import csv
with open('test.csv') as f:
q = csv.reader(f)
采纳答案by Martijn Pieters
You imported a differentcsv
module, not the one in the standard library. Perhaps you named your own script csv.py
for example.
您导入了不同的csv
模块,而不是标准库中的模块。例如,也许您命名了自己的脚本csv.py
。
Find out what is imported instead by printing out the filename of the module:
通过打印模块的文件名找出导入的内容:
import csv
print(csv.__file__)
If that's not in the standard library, rename or delete this file, and remove the csv.pyc
file if there is one next to it.
如果该文件不在标准库中,请重命名或删除该文件,csv.pyc
如果旁边有该文件,则将其删除。