Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #81521
| Date | 2014-11-25 13:07 -0500 |
|---|---|
| From | Dave Angel <davea@davea.name> |
| Subject | Re: Dictionary error |
| References | <CAAmLL-J-t5YN+FXYaYWYenMbo9gFRvsy3kDkfkiMMLXxqVwdww@mail.gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.16290.1416938881.18130.python-list@python.org> (permalink) |
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
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Dictionary error Dave Angel <davea@davea.name> - 2014-11-25 13:07 -0500
csiph-web