L
Lorenzo Di Gregorio
Hello,
I've been using Python for some DES simulations because we don't need
full C speed and it's so much faster for writing models. During
coding I find it handy to assign a variable *unless it has been
already assigned*: I've found that this is often referred to as "once"
assigment.
The best I could come up with in Python is:
try:
variable
except NameError:
variable = method()
I wonder if sombody has a solution (trick, whatever ...) which looks
more compact in coding. Something like:
once(variable, method)
doesn't work, but it would be perfect. Of course I can preprocess the
Python code but an all-Python solution would be more handy.
Any suggestions?
Thx in advance,
Lorenzo
I've been using Python for some DES simulations because we don't need
full C speed and it's so much faster for writing models. During
coding I find it handy to assign a variable *unless it has been
already assigned*: I've found that this is often referred to as "once"
assigment.
The best I could come up with in Python is:
try:
variable
except NameError:
variable = method()
I wonder if sombody has a solution (trick, whatever ...) which looks
more compact in coding. Something like:
once(variable, method)
doesn't work, but it would be perfect. Of course I can preprocess the
Python code but an all-Python solution would be more handy.
Any suggestions?
Thx in advance,
Lorenzo