A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2008-May/079811.html below:

[Python-Dev] Iterable String Redux (aka String ABC)

[Python-Dev] Iterable String Redux (aka String ABC) [Python-Dev] Iterable String Redux (aka String ABC)Armin Ronacher armin.ronacher at active-4.com
Tue May 27 21:32:54 CEST 2008
Hi,

Strings are currently iterable and it was stated multiple times that this is a
good idea and shouldn't change.  While I still don't think that that's a good
idea I would like to propose a solution for the problem many people are
experiencing by introducing an abstract base class for strings.

Basically *the* problematic situation with iterable strings is something like
a `flatten` function that flattens out every iterable object except of strings.
Imagine it's implemented in a way similar to that::

    def flatten(iterable):
        for item in iterable:
            try:
                if isinstance(item, basestring):
                    raise TypeError()
                iterator = iter(item)
            except TypeError:
                yield item
            else:
                for i in flatten(iterator):
                    yield i

A problem comes up as soon as user defined strings (such as UserString) is
passed to the function.  In my opinion a good solution would be a "String"
ABC one could test against.


Regards,
Armin

More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4