[Python-ideas] strings as iterables - from str.startswith taking any iterator instead of just tuple

Andrew Barnert abarnert at yahoo.com
Fri Jan 3 18:27:21 CET 2014


On Jan 3, 2014, at 6:39, Nick Coghlan <ncoghlan at gmail.com> wrote:

> The Iterable suffix would indicate directly that this wasn't related
> to concurrency.

I don't know; something whose iter was guaranteed to return a iterator that I could next without synchronizing could be pretty handy. ;)

More seriously, I think a strength of your original version was having a single abstract type for both non-iterables and things that are iterable but you sometimes don't want to treat that way. A flatten function that uses "not
isinstance(x, Iterable) or isinstance(x, AtomicIterable)" is less obvious than one that just uses "isinstance(x, Atomic)", and will be a source of 10x as many stupid "oops I used and instead of or" type bugs.

If there really is no acceptable name for the easier concept, the tradeoff could be worth it anyway, but I think it's worth trying harder for one 

One last question to bring up: Is there a reasonable/common use case where you do want to flatten multi-char strings to single-char strings, but then want to treat single-char strings as atoms? I can certainly imagine toy cases like that, but it could easily be so rarely useful that it's ok to leave that clumsy to write.


More information about the Python-ideas mailing list