Skip to Content
전문가를 위한 파이썬(2판)
book

전문가를 위한 파이썬(2판)

by 루시아누 하말류, 강권학
November 2024
Beginner to intermediate
1064 pages
25h 21m
Korean
Hanbit Media, Inc.
Content preview from 전문가를 위한 파이썬(2판)
985
23
속성 디스크립터
예제
23-7
bulkfood
_
v5
.
py
:
Quantity
NonBlank
디스크립터를 사용하는
LineItem
import model_v5 as model ❶
class LineItem:
description = model.NonBlank() ❷
weight = model.Quantity()
price = model.Quantity()
def __init__(self, description, weight, price):
self.description = description
self.weight = weight
self.price = price
def subtotal(self):
return self.weight * self.price
❶ 더 간결한 이름으로
model
_
v5
모듈을 임포트한다.
model
.
NonBlank
()
를 사용한다. 나머지 코드는 바뀐 게 없다.
이 장에서 지금까지 보아온
LineItem
예제들은 데이터 속성을 관리하는 데 디스크립터를 사용
하는 전형적인 방법을 보여 준다.
Quantity( )
같은 디스크립터는 오버라이딩 디스크립터라
고 부른다.
__set__( )
메서드가 관리 대상 인스턴스에 있는 같은 이름의 인스턴스 속성의 설
정하는 것을 오버라이드 (즉, 가로채고 뒤엎기)하기 때문이다. 그러나 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

전문가를 위한 리액트

전문가를 위한 리액트

테자스 쿠마르
고성능 파이썬(2판)

고성능 파이썬(2판)

오현석, 미샤 고렐릭, 이안 오스발트

Publisher Resources

ISBN: 9791169211772