I want to ask if this is the best way of writing a get/ set function for a class static field, that is a property of the class instance, not the class itself?
class MyClass:
__static_field = "something"
def __init__(self):
pass
@staticmethod
def get_static_field():
return MyClass.__static_field
def get_static_field_with_instance(self):
return self.__class__.__static_field
def set_static_field_with_instance(self, new_value):
self.__class__.__static_field = new_value
Here is some output:
print(MyClass.get_static_field())
>>> something
obj = MyClass()
print(obj.get_static_field_with_instance())
>>> something
obj.set_static_field_with_instance("smething new")
print(obj.get_static_field_with_instance())
>>> something new