Bizzare lst length problem

Ben Benjamin.Barker at gmail.com
Sun Oct 8 08:54:25 EDT 2006


...and when I print out the string, it is still formatted as one would
expect a list to be:

<type 'str'> "['01', '02', '03', '04']"



Ben wrote:
> Ah... my list is a string. That explains the len() results, but not why
> it is a string in the dirst place.
>
> I have a dictionary containing a number of instances of the following
> class as values:
>
> class panel:
>     mops =[]
>
>     def __init__(self,number,level,location,mops,matrix):
>          self.number=number
>          self.level=level
>          self.location=location
>          self.mops=mops
>          self.matrix=matrix
>
>
> abve mops is a list, yet when I access it it is a string...
>
>
>
> Fredrik Lundh wrote:
> > Ben wrote:
> >
> > > The output from this would be (for a given key value):
> > >                 Number:	181
> > >                 Level:	ovride+supvis
> > >                 Location:	 mons=4 v8.0 3rd floor
> > >                 MOPS:	['287', '288', '289', '290']
> > >                 List Length:	28
> > >                 Matrix:	kng
> > >
> > > This is really odd...my len(v.mops) ought to return 4 (4 elements in
> > > the list).
> >
> > adding a
> >
> >      print type(v.mops), repr(v.mops)
> >
> > debug statement might provide you with the clues you need.
> >
> >  > In fact it returns 28. looking at outputs from lots of
> > > records, it seems that the length is almost always 7 time too great
> > > (28/7=4)....but not always.
> >
> >  >>> len("['287',")
> > 7
> >  >>> len(" '288',")
> > 7
> >  >>> len(" '289',")
> > 7
> >  >>> len(" '290']")
> > 7
> > 
> > </F>




More information about the Python-list mailing list