我得到了一个 csv 文件,但我想跳过第一行数据并继续下一行。这是我的代码:
def read_csv(inputfile):
return list(csv.reader(inputfile)) #<-----
def generate_xml(reader,outfile):
root = Element('Solution')
root.set('version','1.0')
tree = ElementTree(root)
head = SubElement(root, 'DrillHoles')
description = SubElement(head,'description')
current_group = None
i = 1
for row in reader.next(): #<-----
x1,y1,z1,x2,y2,z2,cost = row
if current_group is None or i != current_group.text:
current_group = SubElement(description, 'hole',{'hole_id':"%s"%i})
collar = SubElement(current_group,'collar')
toe = SubElement(current_group,'toe')
cost1 = SubElement(current_group,'cost')
collar.text = ','.join((x1,y1,z1))
toe.text = ','.join((x2,y2,z2))
cost1.text = cost
i+=1
head.set('total_holes', '%s'%i)
indent.indent(root)
tree.write(outfile)
如您所见,我将 csv 文件作为列表返回,然后将其传递给 generate_xml 函数。但是,当我运行完整的程序时,有一个
error: 'list' object has no attribute 'next'