> I'm trying to implement __iter__ on an abstract base class while I 
> don't
> know whether subclasses support that or not.
> Hope that makes sense, if not, this code should be clearer:
>
> class Base:
>     def __getattr__(self, name):
>         if name == "__iter__" and hasattr(self, "Iterator"):
>             return self.Iterator
>         raise AttributeError, name
>
> class Concrete(Base):
>     def Iterator(self):
>         yield 1
>         yield 2
>         yield 3

I don't know how to achieve it, but why don't you simply use

class Base:
        pass

class Concrete(Base):
        def __iter__(self) :
                yield 1
                yield 2
                yield 3


What is the advantage to have a baseclass that essentially does
some method renaming __iter__ ==> Iterator?

- harold -

--
Always remember that you are unique;
just like everyone else.
--

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to