Bug? If not, how to work around it?
Steven Taschuk
staschuk at telusplanet.net
Wed Aug 6 21:43:08 EDT 2003
Quoth Mark Day:
[...]
> I'm guessing that iter() is looking for an __iter__ attribute without
> going through __getattr__ to find it. [...]
Right. This is normal for special methods when invoked by special
notations (e.g., __len__ invoked by way of len(), __add__ invoked
by way of +, etc.).
> [...] So, I tried adding the following
> method to the Test class:
>
> def __iter__(self):
> return self.__obj.__iter__
Well, you have to actually call __iter__ to get the iterator:
def __iter__(self):
return self.__obj.__iter__()
(This makes iter(testobj) not quite the same as
iter(testobj.__obj) for new-style instances, mind you.)
--
Steven Taschuk staschuk at telusplanet.net
"Telekinesis would be worth patenting." -- James Gleick
More information about the Python-list
mailing list