I know how to use property in case of instance variable
class A():
_foo=3
@property
def foo(self):
return self.foo
a = A()
print(a.foo)
it show _foo
3
but i don't know how to use property in case of class variable
class A():
_foo=3
@property
def foo(cls):
return cls._foo
print(A.foo)
it show property object not 3
<property object at 0x7fba8c19ea70>
how to generate class variable getter/setter?
I found a way in here
class MetaFoo(type):
@property
def thingy(cls):
return cls._thingy
class Foo(object, metaclass=MetaFoo):
_thingy = 23
print(Foo.thingy)
it show
23
but i want more simple ways.