[Python-3000] Proposal to add __str__ method to iterables.

Benjamin Peterson musiccomposition at gmail.com
Wed May 28 14:00:11 CEST 2008


On Tue, May 27, 2008 at 10:48 PM, Carl Johnson <carl at carlsensei.com> wrote:
> - - - -
>
> Potential downside #1: Don't try to print an infinite object, like
> itertools.count().
>
> Other potential downside #2: This makes "".join(l) obsolete.

No, it wouldn't. What is people want to join sequences with something
other than a whitespace or whatever you propose.
>
> Regarding #1: Do a repr instead.
>
> Regarding #2: I don't consider that to be a bad thing actually. I think
> doing "".join is very unnatural for people new to Python, and I think that
> even as people who are used to Python, I think we should admit that it's a
> little weird to join list members in that way.

It's good to have join on string object because then any iterable can
be joined. It doesn't require the sequence to implement it.
>
> In terms of actual implementation, this could also be done by having the str
> class look for a __str__ method then a __iter__ method and only then use
> __repr__ as the final fallback instead of falling back to __repr__ as is
> done now. That might be easier than adding __str__ methods to all iterables.
>
> - - - -
>
> Incidentally, I think the idea that str(["1", "2"]) should return "[1, 2]"
> is a terrible idea. Where's the use case for that? When would you ever need
> to print that? It should return "12", which actually does have a use case as
> the replacement for "".join(["1", "2"]).

However, it's not expected.
> _______________________________________________
> Python-3000 mailing list
> Python-3000 at python.org
> http://mail.python.org/mailman/listinfo/python-3000
> Unsubscribe:
> http://mail.python.org/mailman/options/python-3000/musiccomposition%40gmail.com
>



-- 
Cheers,
Benjamin Peterson
"There's no place like 127.0.0.1."


More information about the Python-3000 mailing list