python for loop printing list character instead of element -


this question has answer here:

i have list of dictionaries of when want print list index element of key in dictionary, output index of character , not element.

reader = csv.dictreader(mycsvfile, fieldnames)         row in reader:             print row 

example output:

{'name':'tom','numbers':"['1','2','3']"} #row 

print row['numbers']

['1',2','3'] #correct 

print row['numbers'][0]

[           #wrong 

how convert row['numbers'] list?

that's okay:

>>> row = {'name':'tom','numbers':['1','2','3']} >>> row['numbers'] ['1', '2', '3'] >>> row['numbers'][0] '1' >>> row['numbers'][1] '2' >>> row['numbers'][2] '3' >>>  

Comments

Popular posts from this blog

Load Balancing in Bluemix using custom domain and DNS SRV records -

oracle - pls-00402 alias required in select list of cursor to avoid duplicate column names -

python - Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>] error -