Data Transfer Object
2016.05.11 by techbard
@property
# Data Transfer Object class Pool:def __init__(self, **kwargs):self.__dict__ = kwargs m = Pool(one=1, two=2, three=3)m.four=4print(m.one)print(m.two, m.three) # 결과12 3
Python 2016. 5. 11. 15:29
# 멤버 변수와 같은 이름의 getter, setter 함수를 정의해서# 외부에서는 멤버를 직접 액세스하는 것처럼 보이지만# 사실상 동일 이름의 함수를 호출해서 액세스 가능한 인터페이스를 제공하는 것# 메소드로 별도 구현할 수 있으나 코드가 복잡해질 우려가 있음 class Prop():@propertydef value(self):return self._value @value.setterdef value(self, value):self._value = value @value.deleterdef value(self):del self._value p1 = Prop()p1.value = 1print(p1.value) # 결과1 # property를 사용하는 두 번째 방법# legacy 코드가 있을때 크게 바꾸지..
Python 2016. 5. 11. 14:08