lazy evaluation of a variable
gelonida at gmail.com
Sun Jun 17 23:35:12 CEST 2012
I'm not sure whether what I ask for is impossible, but would know how
others handle such situations.
I'm having a module, which should lazily evaluate one of it's variables.
Meaning that it is evaluated only if anybody tries to use this variable.
At the moment I don't know how to do this and do therefore following:
####### mymodule.py #######
var = None
if var is not None:
var = something_time_consuming()
Now the importing code would look like
var = mymodule.get_var()
The disadvantage is, that I had to change existing code directly
accessing the variable.
I wondered if there were any way to change mymodule.py such, that the
importing code could just access a variable and the lazy evaluation
would happen transparently.
var = mymodule.var
Thanks in advance for you suggestions
More information about the Python-list