Data Descriptors Beat the Instance Dict
class NonDataDesc:
def __get__(self, obj, objtype=None):
return "from non-data descriptor"
class DataDesc:
def __get__(self, obj, objtype=None):
return "from data descriptor"
def __set__(self, obj, value):
pass
class Example:
nd = NonDataDesc()
dd = DataDesc()
e = Example()
e.__dict__["nd"] = "instance value"
e.__dict__["dd"] = "instance value"
print(e.nd)
print(e.dd)
What do the two print calls output, in order?
Sign in to answer questions and track your progress
Sign In