私はこのコードを持っています。
class NumberDescriptor(object):
def __get__(self, instance, owner):
name = (hasattr(self, "name") and self.name)
if not name:
name = [attr for attr in dir(owner) if getattr(owner,attr) is self][0]
self.name = name
return getattr(instance, '_' + name)
def __set__(self,instance, value):
name = (hasattr(self, "name") and self.name)
if not name:
owner = type(instance)
name = [attr for attr in dir(owner) if getattr(owner,attr) is self][0]
self.name = name
setattr(instance, '_' + name, int(value))
class Insan(object):
yas = NumberDescriptor()
a = Insan()
print a.yas
a.yas = "osman"
print a.yas
行で最大再帰深度エラーが発生していますname = [attr for attr in dir(owner) if getattr(owner,attr) is self][0]
。その行で、現在の記述子インスタンスに使用されている変数の名前を取得したいと思います。誰かが私がここで間違っていることを見ることができますか?