我有一些函数可以解析带有程序数据输出的文本文件。显然,在解析时,我会在文本中寻找一些标记数据的模式。但是,如果所需的行没有以任何方式标记,并且只能以类似于‘从该行算起的第三行,以'data’关键字‘开始’的方式定义,我将使用next()函数对这些行进行计数(例如,如果我需要倒数三行,则将有三个line= next(fo)语句。示例函数参见示例函数: with open(fn, 'r') as inp:
63651000000.0,63651000000.0,153.1,0,0,0,0,0,0,5,1,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 File "csv2libsvm.py", line 47, in <module>AttributeError: '_csv.reader'
#replace the line containing xxx with 'something' line = next(myFile, "") # move to the next line
line = line2 #replace the next line with 'stg'原因来自于推进迭代的next(),因此我的脚本在错误的地方进行更改。这