人生の敗北者でも使えるPythonのお勉強 Part3
■ このスレッドは過去ログ倉庫に格納されています
0414デフォルトの名無しさん
NGNG行われるように manage された属性値 だと思います
def getAgeSabaYomi(aFem):
return int(aFem.trueAge * 0.9)
def setAge(aFem, age):
if age < 20:
raise AttributeError, "Saba Yomosugidesu!"
aFem.trueAge = age
class Girl(object):
def __init__(self):
self.trueAge = 20
age = property(getAgeSabaYomi, setAge)
>>> g = Girl()
>>> print g
<__main__.Girl object at 0x00810500>
>>> print g.age
18
>>> g.age = 30
>>> print g.age
27
>>> g.age = 17
Traceback (most recent call last):
File "<stdin>", line 23, in ?
File "<stdin>", line 6, in setAge
AttributeError: Saba Yomosugidesu!
■ このスレッドは過去ログ倉庫に格納されています