[Python-3000] callable()

Guido van Rossum guido at python.org
Fri Jul 21 03:48:16 CEST 2006


On 7/20/06, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> Walter Dörwald wrote:
>
> > I don't know about __call__, but str and unicode don't have __iter__,
> > list, tuple and dict do:
>
> That's probably because str and unicode don't do their
> own iteration, but rely on the fallback implementation.
> In which case it's perfectly correct for them not to
> have an __iter__ method.
>
> If you want to test whether something is iterable, it's
> not enough to test for __iter__ -- you also need to
> test for __len__ and __getitem__ as an alternative.
> Which means it might make sense to have an iterable()
> function which does that.

And that's a problem, because if uses those to implement a mapping, it
isn't reasonably iterable with just those.

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-3000 mailing list