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, Thomas Heller [EMAIL
[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 want?
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 subclasses
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 AttributeError,
[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 abstract base class
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 == __iter__
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):
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
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.
--
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):
...
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 -
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 hasattr(self,
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 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 -
15 matches
Mail list logo