Use property ()
as just a function, not a decorator.
Used in SQLAlchemy.
from operator import attrgetter
class A:
def __init__(self):
self.foo = "foo"
f = property(attrgetter("foo"), doc="An alias for the :attr:`.foo` attribute.")
if __name__ == "__main__":
help(A.f)
a = A()
print("A.foo:", a.foo)
print("A.f:", a.f)
Execution example.
$ python sample_alias.py
Help on property:
An alias for the :attr:`.foo` attribute.
A.foo: foo
A.f: foo
Recommended Posts