Dictionary error

Dave Angel davea at davea.name
Tue Nov 25 13:07:48 EST 2014


On 11/25/2014 04:34 AM, Thuruv V wrote:
> Please Clarify the 'TypeError: zip argument #1 must support iteration'
>
>
> 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)
>     values = sheet.cell(row = i,column = 5)
>     x.append(keys.value)
>     y.append(values.value)
>     i +=1
>     mydict = dict(zip(keys,values)print mydict
>
>
>
Your email program mangled the code.  Please use text mode when posting 
here.

It's also generally useful to include the full traceback instead of just 
a portion of the error message.  And tell us the Python version in case 
it matters.

As others have pointed out, zip expects two iterables.  My guess is that 
you intended the mydict= assignment to be AFTER the while loop has 
ended, and that you intended to use x and y, rather than the 
poorly-named keys and values.

And if that's the case, you could simplify the code a great deal by just 
adding things to the dict in the first place instead of building two 
lists first.



-- 
DaveA



More information about the Python-list mailing list