Dictionary error

Steven D'Aprano steve+comp.lang.python at pearwood.info
Tue Nov 25 12:30:31 CET 2014


Thuruv V wrote:

> Please Clarify the 'TypeError: zip argument #1 must support iteration'

Try it at the interactive interpreter:

py> zip('abc', [1, 2, 3])  # works fine
[('a', 1), ('b', 2), ('c', 3)]


But:

py> zip(1000, [1, 2, 3])  # fails
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: zip argument #1 must support iteration


So the first argument to zip is not a string or a list, it is something like
an int, or None, or a boolean flag. You'll need to inspect the argument to
see what it is.


> import openpyxl
> 
> book = openpyxl.load_workbook('c:/users/c_thv/desktop/tax.xlsx')
> sheet = book.get_sheet_by_name('Thilip')
> cell = sheet.cell(row=2,column = 4)
> i = 2
> x = []
> y = []while i < 10:
>    keys = sheet.cell(row=i,column = 4)

Insert a line here:

    print keys, type(keys)


and see what it prints.


>    values = sheet.cell(row = i,column = 5)
>    x.append(keys.value)
>    y.append(values.value)
>    i +=1
>    mydict = dict(zip(keys,values)print mydict



-- 
Steven




More information about the Python-list mailing list