working with classes, inheritance, _str_ returns and a list

Frank Millman frank at chagford.com
Mon Jan 16 01:03:19 EST 2017


"Frank Millman"  wrote in message news:o5hnbq$q36$1 at blaine.gmane.org...
>
> "Frank Millman"  wrote in message news:o5hlh4$1sb$1 at blaine.gmane.org...
> >
> > If you are saying -
> >     for item in list:
> >         print(item)
> >
> > you can say instead -
> >   for item in list:
> >         print(str(item))
> >
>
> This is not correct, sorry.
>
> print(item) will automatically print the string representation of item, so 
> it makes no difference.
>
> The principle is still correct, though.
>
> If you want to convert what you call the memory address of the item to the 
> string representation, just wrap it in str(...)
>

I keep thinking of something else just after I have posted - sorry about 
that.

When you say you print the list, maybe you are literally doing the 
following -
    print(list)

In that case, the solution is to turn it into a list comprehension, and 
apply str() to each item -
    print([str(item) for item in list])

Frank




More information about the Python-list mailing list