Python attribute alias

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

Python attribute alias
Python
attribute
attribute
Make Python dict accessible by Attribute
kafka python
Python basics ⑤
python + lottery 6
Built-in python
Python comprehension
Python technique
Studying python
Python 2.7 Countdown
Python memorandum
Python FlowFishMaster
Python service
[Python] Attribute Error:'list' object has no attribute'replace'
python function ①
Python basics
Python memo
ufo-> python (3)
Python comprehension
install python
Python Singleton
Python basics ④
Python Memorandum 2
python memo
Python Jinja2
Python increment
python tips
Installing Python 3.4.3.
Try python
Python memo
Python iterative
Python algorithm
[Python] Variables
Python functions
Python sys.intern ()
Python decimals
python underscore
Python summary
Start python
[Python] Sort
Note: Python
Python basics ③
Python basics
[Scraping] Python scraping
Python update (2.6-> 2.7)
Python memorandum
python learning
Hannari Python 2020
Weighted Random Extraction: Walker's Alias Method (Python)
python memorandum
Download python
python memorandum
Python memo
started python
Python #JSON
python quiz
Python note
Python string