简体   繁体   English

AttributeError:'_io.TextIOWrapper'对象没有属性'reader'

[英]AttributeError: '_io.TextIOWrapper' object has no attribute 'reader'

Couldn't get what wrong in the code, as csv module has a csv.reader() function as per the documentation . 找不到错误的代码,因为csv模块根据文档具有csv.reader()函数。 But I am still getting this error: 但我仍然收到此错误:

Traceback (most recent call last):
  File "test_csv.py", line 4, in <module>
    read = csv.reader(csv, delimiter = ',')
AttributeError: '_io.TextIOWrapper' object has no attribute 'reader'

My code: 我的代码:

import csv

with open('test_csv.csv') as csv:
    read = csv.reader(csv, delimiter = ',')
    for row in read:
        print(row)

You re-bound the name csv in the as target: 您在as目标中重新绑定了名称csv

with open('test_csv.csv') as csv:

This masks the module name, so csv.reader is resolved on the file object . 这将屏蔽模块名称,因此csv.reader 在文件对象上解析。

Use a different target: 使用其他目标:

with open('test_csv.csv') as csvfile:
    read = csv.reader(csvfile, delimiter = ',')
    for row in read:
        print(row)

暂无
暂无

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

相关问题 Python-错误-AttributeError:“ _ io.TextIOWrapper”对象没有属性“插入” - Python - Error - AttributeError: '_io.TextIOWrapper' object has no attribute 'insert' AttributeError: &#39;_io.TextIOWrapper&#39; 对象没有 txt 文件的属性 &#39;lower&#39; - AttributeError: '_io.TextIOWrapper' object has no attribute 'lower' for txt file Python问题:AttributeError:&#39;_ io.TextIOWrapper&#39;对象没有属性&#39;split&#39; - Python Issue: AttributeError: '_io.TextIOWrapper' object has no attribute 'split' AttributeError:&#39;_io.TextIOWrapper&#39;对象没有属性&#39;show&#39; - AttributeError: '_io.TextIOWrapper' object has no attribute 'show' 错误:AttributeError:&#39;_io.TextIOWrapper&#39;对象没有属性&#39;split&#39; - ERROR: AttributeError: '_io.TextIOWrapper' object has no attribute 'split' AttributeError:&#39;_io.TextIOWrapper&#39;对象没有属性&#39;append&#39; - AttributeError: '_io.TextIOWrapper' object has no attribute 'append' 什么是“AttributeError:&#39;_ it.TextIOWrapper&#39;对象在python中没有属性&#39;replace&#39;”? - What is a “ AttributeError: '_io.TextIOWrapper' object has no attribute 'replace' ” in python? Python-AttributeError:“ _ io.TextIOWrapper”对象没有属性“ append” - Python - AttributeError: '_io.TextIOWrapper' object has no attribute 'append' AttributeError:&#39;_io.TextIOWrapper&#39;对象没有属性&#39;append&#39;吗? - AttributeError: '_io.TextIOWrapper' object has no attribute 'append'? AttributeError:&#39;_ io.TextIOWrapper&#39;对象没有属性&#39;lower&#39; - AttributeError: '_io.TextIOWrapper' object has no attribute 'lower'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM