[Tutor] Building Starships -- object of type 'int' has no len()

Marc Tompkins marc.tompkins at gmail.com
Wed Aug 20 22:26:07 CEST 2014


On Aug 20, 2014 12:07 PM, "Terry--gmail" <terry.kemmerer at gmail.com> wrote:
>
> Alan Gauld
>
> Hi!
> We are not quite out of the woods on this last example you gave me. It
now seems to be complaining
> that it doesn't want to append an integer to the list or that this isn't
the place to use '.append'  -- I am probably interpreting it's complaint
wrong:
>
> Python 3.3
>
> If I run this last piece of code that we just added 'enumerate(row)' to:
>
> lens = [0] * len(catalog2[0])
> for row in catalog2:
>
>     for col, item in enumerate(row):
>         print(col, item, len(item))
>
>         lens[col].append(len(item))
> lens = [max(col) for col in lens]
>
> My result is:
>
> 0 Drives 6         <<---- my print statement result
>
> Traceback (most recent call last):
>   File "/home/justme/1a_Computer_Related/Python/scripts/scratch.py", line
43, in <module>
>     lens[col].append(len(item))
> AttributeError: 'int' object has no attribute 'append'
>
Once again you're confusing the list with its contents.  lens is a list;
lens[col] is an integer.  lens.append(whatever) should do the trick.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140820/f9c641db/attachment.html>


More information about the Tutor mailing list