gpt4 book ai didi

python - 属性错误 : '_io.TextIOWrapper' object has no attribute 'next'

转载 作者:太空宇宙 更新时间:2023-11-04 00:37:59 25 4
gpt4 key购买 nike

使用我在 Python 2 中编写的函数,我试图连接 csv 文件:

def concat_csv():
"""
A function to concatenate the previously wrangled csv files in current working dir
"""
with open('2017_oldnew.csv', 'a') as f_out:
# First file
with open('old.csv') as f_read:
for line in f_read:
f_out.write(line)
# Second file
with open('new.csv') as f_read:
f_read.next()
for line in f_read:
f_out.write(line)

但是,运行这个 Python 3 会给我一条错误消息:

---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-110-a5a430e1b905> in <module>()
1 # Concatenate the files
----> 2 concat_csv()

<ipython-input-109-9a5ae77e9dd8> in concat_csv()
10 # Second file
11 with open('new.csv') as f_read:
---> 12 f_read.next()
13 for line in f_read:
14 f_out.write(line)

AttributeError: '_io.TextIOWrapper' object has no attribute 'next'

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com