Bug? If not, how to work around it?

Gonçalo Rodrigues op73418 at mail.telepac.pt
Thu Aug 7 12:15:41 CEST 2003

On Thu, 07 Aug 2003 00:54:03 +0100, Gonçalo Rodrigues
<op73418 at mail.telepac.pt> wrote:

>On Wed, 6 Aug 2003 19:46:39 -0400, "Terry Reedy" <tjreedy at udel.edu>
>>"Gonçalo Rodrigues" <op73418 at mail.telepac.pt> wrote in message
>>news:upv2jv4eeusj7bli30j7a7ikd0cq3njvm4 at 4ax.com...
>>> >I changed the __iter__ method to the following, and it seems to do
>>> >you want:
>>> >
>>> >    def __iter__(self):
>>> >        return iter(self.__obj)
>>> But this is precisely what I don't want to do.
>>If you don't want to do what works,
>>why ask us to bother answering?
>Because it may not work. That is, the use case I have in mind serves
>as proxy for an object that may or may not have __iter__. IOW if I
>stick __iter__ I have to code a second class, etc... etc... Oh well...

Replying to myself:

Just to make things clearer, having iter(self.__obj) as in

def __iter__(self):
    return iter(self.__obj)

Would mean that my proxy class would become an iterable. And that is
not what I want because *other* parts in my code check that an object
is in iterable by looking for __iter__. Suffice it to say that fake
iterables, although not the worst thing in the world, are not
desirable. Maybe this means that I have to approach things in another
way. Humpf.

With my best regards,
G. Rodrigues

More information about the Python-list mailing list