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

Lennart Regebro regebro at gmail.com
Sat May 31 15:52:59 CEST 2008


On Wed, May 28, 2008 at 5:48 AM, Carl Johnson <carl at carlsensei.com> wrote:
> Proposed behavior of the __str__ method for iterables is that it returns the
> result of "".join(str(i) for i in self).

In 8-9 years of python programming I have probably never needed to do
"".join(str(i) for i in self), so even if there was a __str__ on
iterables, this seems to me to be a particularily useless default. :)

> In order to replicate the behavior of filter with a comprehension

Instead of running filter on a string, you can replace the offending
character with emptyness.

filter(lambda c: c!="a", "abracadbra")
'brcdbr'

"abracadbra".replace('c', '')
'brcdbr'

I find using filter on a string kinda strange, I have to say. How
often do you have to filter away certain characters in s a string?
Never happened to me.

-- 
Lennart Regebro: Zope and Plone consulting.
http://www.colliberty.com/
+33 661 58 14 64


More information about the Python-3000 mailing list