티스토리 뷰
참조: https://stackoverflow.com/questions/3798835/understanding-get-and-set-and-python-descriptors
The descriptor is how Python's property
type is implemented. A descriptor simply implements __get__
, __set__
, etc. and is then added to another class in its definition (as you did above with the Temperature class). For example:
temp=Temperature()
temp.celsius #calls celsius.__get__
Accessing the property you assigned the descriptor to (celsius
in the above example) calls the appropriate descriptor method.
instance
in __get__
is the instance of the class (so above, __get__
would receive temp
, while owner
is the class with the descriptor (so it would be Temperature
).
You need to use a descriptor class to encapsulate the logic that powers it. That way, if the descriptor is used to cache some expensive operation (for example), it could store the value on itself and not its class.
'BackEnd > Python' 카테고리의 다른 글
비교 Selenium & Scrapy (0) | 2019.03.16 |
---|---|
프로젝트 시작시 도움을 줄 수 있는 Cookiecutter (0) | 2019.03.16 |
[퍼옴] 클래스변수와 인스턴스 변수 (0) | 2018.06.12 |
[퍼옴] 파이썬 - 제너레이터 (Generator) (0) | 2018.04.16 |
[퍼옴] 파이썬 - 데코레이터 (Decorator) (0) | 2018.04.16 |
- 모두의딥러닝
- Maven
- BigData
- tensorflow
- executor
- TDD
- Docker
- serverless
- memory
- web
- Configuration
- Gradle
- 점프투파이썬
- spark
- 텐서플로우
- spring
- NIO
- AI
- AWS
- 중앙정보처리학원
- javascript
- Java
- 머신러닝
- ML
- python
- mysql
- Error
- 파이썬
- mybatis
- API
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |