Error message <exceptions.TypeError unpack non-sequence>

Terry Reedy tjreedy at udel.edu
Sat Feb 7 02:58:14 CET 2004


"ahsan Imam" <ahsan.imam at newtimes.com> wrote in message
news:788bd2d4.0402061352.676d8566 at posting.google.com...
> Josiah Carlson <jcarlson at nospam.uci.edu> wrote in message
news:<bvv2dr$7oa$1 at news.service.uci.edu>...
> > > I am trying to move an application from python 1.5.2 to 2.3. The code
> > > works fine in 1.5.2 but gives the exception (exceptions.TypeError
> > > unpack non-sequence) in python 2.3. I did not write this code so I am
> > > not sure what is happening here.

I do not know of any change in Python that would make code like the below
invalid.  Are you possibly running the program with different input data?
I suggest you insert 'print self.lItems' before the loop to see it *that*
changed (somewhere else in the program).

> > >
> > > Here is the code snippet:
> > >
> > > for (item, agent) in self.lItems:
> > >       lItems.append(interpolate(self._ITEM_FMT, id=str(item)))

self.lItems must contain zero or more (item,agent) *pairs*

> What if there are more than 2 items? How can I do something where
> element 0 and 1 are assigned to (item, agent) and so on?

Yes and no.  You would have to group elements 0 and 1 into a pair, elements
2 and 3 into another (the second), and so on.  There is probably something
in itertools that will do this.  Otherwise, writing your own generator to
do so should be easy enough.  Then write 'for (i,a) in grouper(s.l):' where
grouper is the pair generator.

Terry J. Reedy







More information about the Python-list mailing list