简体   繁体   English

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

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

everybody. 大家 I am currently working to merge the csv files. 我目前正在合并csv文件。 For example, you have files from filename1 to filename100. 例如,您有文件名从filename1到filename100。 I used the following code to combine 100 files and the following error occurred: I'll put the code up first. 我使用以下代码合并了100个文件,并发生了以下错误:我将代码放在第一位。 import csv 导入csv

fout=open("aossut.csv","a")
# first file:
for line in open("filename1.csv"):
    fout.write(line)
# now the rest:    
for num in range(2,101):
    f = open("filename"+str(num)+".csv")
    f.next() # skip the header
    for line in f:
         fout.write(line)
    f.close() # not really needed
fout.close()

And the following error occurred when the above file was executed: 执行上述文件时,发生以下错误:

File "C:/Users/Jangsu/AppData/Local/Programs/Python/Python36-32/tal.py", line 10, in 
<module>
    f.next() # skip the header
AttributeError: '_io.TextIOWrapper' object has no attribute 'next'

I've been working on it for a few days, and I don't know what to do. 我已经研究了几天,但我不知道该怎么办。

The file object doesn't have next method. 文件对象没有next方法。 Instead use next(f) to skip the first line 而是使用next(f)跳过第一行

for num in range(2,101):
    with open("filename"+str(num)+".csv") as f:
        next(f)
        for line in f:
            fout.write(line)

csv库中的方法“ next()”已更新为python 3中的next ()。您可以在以下链接中查看详细信息: https : //docs.python.org/3/library/csv.html

暂无
暂无

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

相关问题 AttributeError: &#39;_io.TextIOWrapper&#39; 对象没有属性 &#39;next&#39; python - AttributeError: '_io.TextIOWrapper' object has no attribute 'next' python 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; - Python says: AttributeError: '_io.TextIOWrapper' object has no attribute ' AttributeError:&#39;_io.TextIOWrapper&#39;对象没有属性&#39;decode&#39; - AttributeError: '_io.TextIOWrapper' object has no attribute 'decode' AttributeError:&#39;_io.TextIOWrapper&#39;对象没有属性&#39;split&#39;错误 - AttributeError: '_io.TextIOWrapper' object has no attribute 'split' error Python:AttributeError:&#39;_ io.TextIOWrapper&#39;对象没有属性&#39;split&#39; - Python: AttributeError: '_io.TextIOWrapper' object has no attribute 'split' Python: AttributeError: '_io.TextIOWrapper' object 没有属性 'readLines' - Python: AttributeError: '_io.TextIOWrapper' object has no attribute 'readLines' AttributeError: '_io.TextIOWrapper' object 没有属性 'content_length' - AttributeError: '_io.TextIOWrapper' object has no attribute 'content_length' AttributeError: '_io.TextIOWrapper' object 没有属性 'rpartition' - AttributeError: '_io.TextIOWrapper' object has no attribute 'rpartition'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM