Python There are some magical ways to do it , They are always surrounded by double underscores , They are object-oriented Of Python Everything . They are special ways to add magic to your classes , If your object implements ( heavy load ) A magic method , Then this method will be automatically used in special cases Python The call .
Defines the behavior when an attribute is deleted
self Represents the object itself ;item Is a string , Indicates the name of the deleted attribute
nothing
Example
class MyTest:
def __delattr__(self, item):
print('{} Property will be deleted '.format(item))
self.__dict__.pop(item)
sample = MyTest()
sample.age = 10
del sample.age
Read gold ETF data This paper