WillWill
WillWill

Reputation: 35

Need help on this error: ValueError: too many values to unpack

from  xlrd import open_workbook
book = open_workbook('Workbook2.csv')
sheet = book.sheet_by_index(0)
keys = [sheet.cell(0,col_index).value for col_index in xrange(sheet.ncols)]
dict_list =[]

for row_index in xrange(1,sheet.nrows):
   d={keys[col_index]: sheet.cell(row_index, col_index).value for col_index in    xrange(sheet.ncols)}
   dict_list.append(d)

print dict_list

for i in range(len(dict_list)):
  for key,val in dict_list[i]:
    print val

Trying to print out the val, but it gives this error: ValueError: too many values to unpack. Anyone that can help?

Upvotes: 0

Views: 841

Answers (1)

user2746752
user2746752

Reputation: 1088

Try, if you're using Python 2:

for key, val in dict_list[i].iteritems():

Or with Python 3:

for key, val in dict_list[i].items():

Alternatively, if you want just the keys, or just the values, you can use dict_list[i].keys() and dict_list[i].values() respectively.

Upvotes: 1

Related Questions