On Thu, 07 Jul 2005 22:04:31 +0200, Thomas Heller <[EMAIL PROTECTED]> wrote:
>[EMAIL PROTECTED] (Bengt Richter) writes:
>
>> On Thu, 07 Jul 2005 09:51:42 +0200, Thomas Heller <[EMAIL PROTECTED]> wrote:
>>
>>>[EMAIL PROTECTED] (Bengt Richter) writes:
>>>
On Wed, 06 Jul 2005 17:57:42 +0200, Tho
[EMAIL PROTECTED] (Bengt Richter) writes:
> On Thu, 07 Jul 2005 09:51:42 +0200, Thomas Heller <[EMAIL PROTECTED]> wrote:
>
>>[EMAIL PROTECTED] (Bengt Richter) writes:
>>
>>> On Wed, 06 Jul 2005 17:57:42 +0200, Thomas Heller <[EMAIL PROTECTED]> wrote:
>>>
I'm trying to implement __iter__ on an
Thomas Heller <[EMAIL PROTECTED]> writes on Wed, 06 Jul 2005 18:07:10 +0200:
> Thomas Heller <[EMAIL PROTECTED]> writes:
> ...
> > class Base:
> > def __getattr__(self, name):
> > if name == "__iter__" and hasattr(self, "Iterator"):
> > return self.Iterator
> > raise
On Thu, 07 Jul 2005 09:51:42 +0200, Thomas Heller <[EMAIL PROTECTED]> wrote:
>[EMAIL PROTECTED] (Bengt Richter) writes:
>
>> On Wed, 06 Jul 2005 17:57:42 +0200, Thomas Heller <[EMAIL PROTECTED]> wrote:
>>
>>>I'm trying to implement __iter__ on an abstract base class while I don't
>>>know whether s
[EMAIL PROTECTED] (Bengt Richter) writes:
> On Wed, 06 Jul 2005 17:57:42 +0200, Thomas Heller <[EMAIL PROTECTED]> wrote:
>
>>I'm trying to implement __iter__ on an abstract base class while I don't
>>know whether subclasses support that or not.
> Will a property or custom descriptor do what you w
Thomas Heller wrote:
> I forgot to mention this: The Base class also implements a __getitem__
> method which should be used for iteration if the .Iterator method in
> the subclass is not available. So it seems impossible to raise an
> exception in the __iter__ method if .Iterator is not found - _
On Wed, 06 Jul 2005 17:57:42 +0200, Thomas Heller <[EMAIL PROTECTED]> wrote:
>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
Thomas Heller wrote:
> 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 hasat
Thomas Heller wrote:
> I forgot to mention this: The Base class also implements a __getitem__
> method which should be used for iteration if the .Iterator method in the
> subclass is not available. So it seems impossible to raise an exception
> in the __iter__ method if .Iterator is not found - __
Something like this:
>>> class Base(object):
... def __getitem__(self, key):
... return key
... def __iter__(self):
... yield self[1]
... yield self['foo']
... yield self[3.0]
...
>>> class ConcreteIterable(Base):
... def __iter__(self):
Why not define an Iterator method in your Base class that does the
iteration using __getitem__, and any subclass that wants to do
something else just defines its own Iterator method? For that matter,
you could just use the __iter__ methods of Base and Concrete instead of
a separate method.
--
ht
I'm not sure I understand why you would want to. Just don't define
__iter__ on your newstyle class and you'll get the expected behavior.
--
http://mail.python.org/mailman/listinfo/python-list
> 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")
Thomas Heller <[EMAIL PROTECTED]> writes:
> 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 ==
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"):
re
15 matches
Mail list logo