このコードは、とで異なる出力を生成しPython 2
ますPython 3
。
class Descriptor(object):
def __get__(self, instance, owner):
print('read')
return 1
def __set__(self, instance, value):
print('write')
def __delete__(self, instance):
print('del')
class C():
a = Descriptor()
c = C()
c.a
c.a = 3
del c.a
c.a
print('finished')
Python2の出力は次のとおりです。
read
read
finished
Python3の場合は次のとおりです。
read
write
del
read
finished
なぜこれがこのように機能しているのですか?記述子は記述子とどのようにPython 2
異なりPython 3
ますか?
http://docs.python.org/release/3.0.1/reference/datamodel.html#invoking-descriptorsはhttp://docs.python.org/reference/とまったく同じものを明確に記述している ため、これも意味がありません。datamodel.html#invoking-descriptors
(これらはとのドキュメントですPython 2.7
。Python 3.0
)