2👍
✅
Think about a way in which you could implement it in a class:
class X(object):
def get_y(self):
return self.y
If you were wanting to create a property y
without actually using the function get_y
as it stands at that point, how might you do it?
class X(object):
def get_y(self):
return self.y
@property
def y(self):
return self.get_y()
This way it is evaluated at runtime.
'l1_s_logcount': property(lambda self: self._get_l1_logcount()),
Or, cutting out the intermediate step,
'l1_s_logcount': property(lambda self: numpy.log10(self.l1_normalized)),
0👍
Also you could take out the function and use it directly
get_l1_logcount = lambda self: numpy.log10(self.l1_normalized)
fields = {
...,
'_get_l1_logcount': get_l1_logcount,
'l1_s_logcount': property(get_l1_logcount),
}
👤okm
Source:stackexchange.com