Le Mercredi 24 Mai 2006 22:37, Scott David Daniels a écrit :
> class Base(object):
> def __init__(self, attr):
> self._attr = attr
> def getattr(self):
> return self._attr
> def attr(self):
> return self.getattr()
> att
Oh! Thanx! Great! this is what i was looking for! :)
Scott David Daniels ha escrito:
> Pablo wrote:
>
> > Second solution: This is what i want, but...
> >
> > class Base(object):
> > def __init__(self, attr):
> > self._attr = attr
> > def getattr(self):
> > return self._at
Pablo wrote:
> Second solution: This is what i want, but...
>
> class Base(object):
> def __init__(self, attr):
> self._attr = attr
> def getattr(self):
> return self._attr
> attr = property(fget=lambda self: self.getattr())
>
> class Derived(Base):
> def getattr(
The reason i would like a different approach to the lambda function is
just a question of personal taste... i dont really like it.
thanx!
--
http://mail.python.org/mailman/listinfo/python-list
Le Mardi 23 Mai 2006 15:55, Pablo a écrit :
> Question: Isn't there an *alternative* way to do it without the lambda
> function?
No, it's good, why shouldn't you use a lambda function ?
Note you can do something like this :
class _virtualgetter :
def __init__(self, name) : self._n =name
Pablo ha escrito:
> Hello all, sorry if this is a faq...
>
> Problem: The intended effect is to override the method 'getattr' in a
> way that i dont need to override the property explicitly too.
>
> class Base(object):
> def __init__(self, attr):
> self._attr = attr
> def getattr(s
Hello all, sorry if this is a faq...
Problem: The intended effect is to override the method 'getattr' in a
way that i dont need to override the property explicitly too.
class Base(object):
def __init__(self, attr):
self._attr = attr
def getattr(self):
return self._attr