[Python-3000] callable()

Greg Ewing greg.ewing at canterbury.ac.nz
Fri Jul 21 03:22:42 CEST 2006


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.

--
Greg


More information about the Python-3000 mailing list