On 01.11.2012, at 22:38, Andrea Crotti wrote:
Seeing the wonderful lazy val in Scala I thought that I should try to get
the following also in Python.
The problem is that I often have this pattern in my code:
class Sample:
def __init__(self):
self._var = None
@property
Seeing the wonderful lazy val in Scala I thought that I should try to
get the following also in Python.
The problem is that I often have this pattern in my code:
class Sample:
def __init__(self):
self._var = None
@property
def var(self):
if self._var is None:
On Thu, Nov 1, 2012 at 3:38 PM, Andrea Crotti andrea.crott...@gmail.com wrote:
What I would like to write is
@lazy_property
def var_lazy(self):
return long_computation()
and this should imply that the long_computation is called only once..
If you're using Python 3.2+, then
On 01Nov2012 21:38, Andrea Crotti andrea.crott...@gmail.com wrote:
| Seeing the wonderful lazy val in Scala I thought that I should try to
| get the following also in Python.
| The problem is that I often have this pattern in my code:
|
| class Sample:
| def __init__(self):
|
If you're using Python 3.2+, then functools.lru_cache probably
...
And if you're on 2.X, you can grab lru_cache from
http://code.activestate.com/recipes/498245-lru-and-lfu-cache-decorators/
--
http://mail.python.org/mailman/listinfo/python-list