I am not 100% sure this is called lazy-evaluation or not, but I am hoping to do this in Python.
I have a "setup wizard" which a user will go through and in turn create some global variables which will be used as parameters in a class.
var = myClass(param1, param2) should not be evaluated until global variables param1 and param2 exist. However, I need var to exist because I am associating var0 = var.func, a function inside myClass. Later on in the application, var0 is called and func() is performed.
Updated
Here is a bit of my code:
class myClass:
def __init__(self, param1, param2):
self.param1 = param1
self.param2 = param2
#------------------------------------------------------------------------
def myFunction(self):
"""
Some work here using self.param1 and self.param2
"""
def myFunction2(self):
"""
Some work here using self.param1 and self.param2
"""
def myFunction3(self):
"""
Some work here using self.param1 and self.param2
"""
myInstance = myClass(PARAM1, PARAM2)
myDict = {}
myDict["key1"] = myInstance.myFunction
myDict["key2"] = myInstance.myFunction2
myDict["key3"] = myInstance.myFunction3
# and so on...
PARAM1 and PARAM2 are populated as global variables by the user through actions inside of a wxPython wizard. The problem is that myInstance cannot be evaluated at initialization because PARAM1 and PARAM2 don’t exist yet. However, the dictionary key’s are being associated to the various functions at initialization because they won’t change over time.
Ideas?
I used the
@staticmethoddecorator to get past this in my code, but I won’t accept it as an answer as I don’t know if this is the best answer at the moment!!and after the user passes through the setup wizard and populated
PARAM1andPARAM2, I can loop through the dictionary and calculate the respective value pair using its associated function by passingPARAM1andPARAM2like so: