lines = node_record.splitlines()
reader = csv.reader(lines, delimiter=',')
rows = []
node_id_pos = -1
for i, row in enumerate(reader):
if len(row) == 2:
return rows
if i == 0:
try:
node_id_pos = row.index('nid')
row[row.index('_start')] = 'start'
row[row.index('_end')] = 'end'
row[row.index('_type')] = 'type'
except:
raise ValueError('Invalid row: {} {}'.format(str(row), row['_id']))
In the code above, when an exception occurs, it print outs the literal string:
raise ValueError('Invalid row: {} {}'.format(str(row), row['_id']))
TypeError: list indices must be integers or slices, not str
Why the row's values are not printed out?