我有一个字典列表,当我想在字典中打印键的列表索引元素时,输出是字符的索引而不是元素。
reader = csv.DictReader(mycsvfile, fieldnames)
for row in reader:
print row
示例输出:
{'name':'tom','numbers':"['1','2','3']"} #row
print row ['numbers']
['1',2','3'] #correct
print row ['numbers'] [0]
[ #wrong
如何将row ['numbers']转换为列表?
答案 0 :(得分:0)
没关系:
>>> row = {'name':'tom','numbers':['1','2','3']}
>>> row['numbers']
['1', '2', '3']
>>> row['numbers'][0]
'1'
>>> row['numbers'][1]
'2'
>>> row['numbers'][2]
'3'
>>>