Python 属性错误:'_io.TextIOWrapper';对象没有属性';下一个';?
大家好。 我目前正在合并csv文件。 例如,您有从filename1到filename100的文件。 我使用以下代码组合了100个文件,出现了以下错误: 我先把密码挂上去。 导入csvPython 属性错误:'_io.TextIOWrapper';对象没有属性';下一个';?,python,csv,Python,Csv,大家好。 我目前正在合并csv文件。 例如,您有从filename1到filename100的文件。 我使用以下代码组合了100个文件,出现了以下错误: 我先把密码挂上去。 导入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("
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()
执行上述文件时发生以下错误:
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'
文件“C:/Users/Jangsu/AppData/Local/Programs/Python/Python36-32/tal.py”,第10行,在
f、 下一步()#跳过标题
AttributeError:“\u io.TextIOWrapper”对象没有属性“next”
我已经做了几天了,不知道该怎么办。文件对象没有
next
方法。使用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)
文件对象没有
next
方法。使用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()。您可以在此链接中看到详细信息:csv库中的方法“next()”在python 3中更新为next()。您可以在这个链接中看到详细信息:
f.next
将在Python2中工作;在Python 3中,next的拼写是\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu。内置函数next
将在两者上都起作用。f.next
将在Python 2中起作用;在Python 3中,next
的拼写是\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu。内置函数next
将对这两个功能都起作用。谢谢。但是有很多问题我很好奇。合并csv文件时,尝试合并相应文件中行列中的值,然后合并行值。如何添加列的值?谢谢。但是有很多问题我很好奇。合并csv文件时,尝试合并相应文件中行列中的值,然后合并行值。如何添加列的值?