class dic1:
def __init__(self,name):
self.name=name
def __get__(self,obj,cls):
return obj.__dict__[self.name].title()
def __set__(self,obj,value):
if not isinstance(value,str):
raise TypeError('you need input string')
obj.__dict__[self.name]=value
class person:
name=dic1('name')
def __init__(self,value):
self.name=value
dict1是描述符,我不明白为什么__get__,__set___所接受的参数是这样,而且返回值为啥是obj.__dict__[self.name]这样
def __init__(self,name):
self.name=name
def __get__(self,obj,cls):
return obj.__dict__[self.name].title()
def __set__(self,obj,value):
if not isinstance(value,str):
raise TypeError('you need input string')
obj.__dict__[self.name]=value
class person:
name=dic1('name')
def __init__(self,value):
self.name=value
dict1是描述符,我不明白为什么__get__,__set___所接受的参数是这样,而且返回值为啥是obj.__dict__[self.name]这样