I have a class definition which defines a static method. I have a field which I would like to initialize with the static method. My default thinking led me to this:
class SomeConcreteClass(object):
some_data = SomeConcreteClass.create_default_data()
@staticmethod
def create_default_data():
return 'Foo'
The problem is that when I run this, I get a NameError: name 'SomeConcreteClass' is not defined. It makes sense as the SomeConcreteClass is just being built. Does this mean I cannot use static init functions? Is there an alternate way which is recommended to handle such a situation?
If
some_datais exactly the output ofcreate_default_data(and assuming the latter is deterministic in the context of your call) then why not just makesome_dataa@property?Alternatively, but not equivalently, you could initialize
some_datafor each instance within__init__.