AttributeError:“模块"对象没有属性“阅读器" [英] AttributeError: 'module' object has no attribute 'reader'

查看:126
本文介绍了AttributeError:“模块"对象没有属性“阅读器"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到了错误:

AttributeError:模块"对象没有属性阅读器")

AttributeError: 'module' object has no attribute '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)

推荐答案

您导入了一个不同 csv模块,而不是标准库中的那个模块.例如,也许您将自己的脚本命名为csv.py.

You imported a different csv module, not the one in the standard library. Perhaps you named your own script csv.py for example.

通过打印模块的文件名来查找导入的内容:

Find out what is imported instead by printing out the filename of the module:

import csv
print(csv.__file__)

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

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.

这篇关于AttributeError:“模块"对象没有属性“阅读器"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆