I am trying to dynamically assign a class variable a value from inside of a class.
class Test:
dynamic_value = get_dynamic_value()
I believe get_dynamic_value() should belong to the Test class. Is there a way to have Test contain this method?
Right now I am using and it is working
def get_dynamic_value():
return 'my dynamic value'
class Test:
dynamic_value = get_dynamic_value()
I would like for Test to contain this method so I have tried to make it both a @classmethod and a @staticmethod and calling it by
class Test:
dynamic_value = Test.get_dynamic_value()
@staticmethod
def get_dynamic_value():
return 'dynamic'
But when trying it using a static method I receive
AttributeError: class Test has no attribute 'get_dynamic_value'
Is there any way to do this? Or is there a better way to handle this?