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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 16:19:50  来源:igfitidea点击:

AttributeError: 'module' object has no attribute 'reader'

pythoncsv

提问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 differentcsvmodule, not the one in the standard library. Perhaps you named your own script csv.pyfor 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.pycfile if there is one next to it.

如果该文件不在标准库中,请重命名或删除该文件,csv.pyc如果旁边有该文件,则将其删除。