Use of lambda functions in OOP, any alternative?
Maric Michaud
maric at aristote.info
Tue May 23 12:18:45 EDT 2006
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
def _call__(self, vself) : return getattr(vself, 'get' + self._n)()
def vprop(name) : return property(fget=_virtualgetter(name))
#anywhere
from ... import vprop
class Base(object):
def __init__(self, attr):
self._attr = attr
def getAttribute(self):
return self._attr
attr = vprop('Attribute')
class Derived(Base):
def getAttribute(self):
return 2*self._attr
--
_____________
Maric Michaud
_____________
Aristote - www.aristote.info
3 place des tapis
69004 Lyon
Tel: +33 426 880 097
More information about the Python-list
mailing list