I am using class to scope data (yap, maybe I should move this to a 2nd module). This class will contain a lot of "constants", however some of them need to be calculated when the script starts.
It would be great if this static method would be run at startup, without me dealing with that. Is there a function called at class creation? (not object creation!)
class Constants:
data = {}
capacity = 0
def createData():
data[1] = "123!"
data[2] = "aaa"
data[3] = "bb"
for i in a:
capacity = capacity + len(i)
#Constants.createData()
print(f"data[2] = {Constants.data[2]}")
Notes:
- The
datais deterministic, and computed. I could create a script that creates a python code... but this is ugly. - I will not instantiate this class, instead I am using it as a scope.
- Note that capacity needs to be computer at runtime. In my real life application - data is much more randomized, and swapped. I also have MIX/MAX values of arrays (again, arrays are populated at runtime, not "compile/write time"
createData()call at the same level as data and capacity definitions.types.SimpleNamespacerather than defining a new class.typesin your case) do initialization?