Infinitely nested containers

random832 at fastmail.us random832 at fastmail.us
Sun Nov 23 07:39:56 CET 2014



On Sun, Nov 23, 2014, at 00:59, Steven D'Aprano wrote:
> >> It works fine now (Python 3.3).
> >> 
> >> py> L = []
> >> py> t = (L, None)
> >> py> L.append(L)
> >> py> L.append(t)  # For good measure.
> >> py> print(t)
> >> ([[...], (...)], None)
> > 
> > This is a tuple in a list in a tuple, not a tuple in a tuple.
> 
> Really? I hadn't noticed.
> 
> *wink*
> 
> It's still a tuple in itself, recursively, and the tuple to str
> conversion
> routine still has to deal with the fact.

Does it, or does it punt to the list to str routine?

Anyway, on python 2.7, print and str do not work the same way for
tuples. I'm remembering more about this issue now, and it was _strictly_
on print, not on str.
>>> t
([[...], ([...], None)], None)
>>> print(t)
([[...], ([...], None)], None)
>>> str(t)
'([[...], (...)], None)'


Notice that print never does (...), only [...]. And if it never finds a
[...]?



More information about the Python-list mailing list