I need to dynamically create class attributes from a DEFAULTS dictionary.
defaults = {
'default_value1':True,
'default_value2':True,
'default_value3':True,
}
class Settings(object):
default_value1 = some_complex_init_function(defaults[default_value1], ...)
default_value2 = some_complex_init_function(defaults[default_value2], ...)
default_value3 = some_complex_init_function(defaults[default_value3], ...)
I could also achive this by having sth. like __init__
for class creation, in order to dynamically create these attributes from dictionary and save a lot of code and stupid work.
How would you do this?
Thank you very much in advance!
cls
in the first example) at the end of the decorator function, don't you? Took me a while to figure out, but unless I do this the class will equalNone
after definition. Am I missing something, like for example some way of supplying the class by reference instead? – Amatruda