To add a static property to a class in Python, you can utilize the @staticmethod
decorator in combination with the @property
decorator. Here is an example:
main.py170 chars8 lines
In the above example, my_static_property
is a static attribute of the class MyClass
. We then define a @staticmethod
with the @property
decorator called static_property
which simply returns the value of my_static_property
.
Now we can access this static property on the class rather than an instance of the class:
main.py68 chars2 lines
gistlibby LogSnag