class A:
def __init__(self, name):
self.name = name
def __setitem__(self, key, value):
self.__dict__[key] = value
def __getitem__(self, item):
self.__dict__.get(‘age‘)
def __delitem__(self, key):
print(‘del obj.__dict__[name]我执行‘)
self.__dict__.pop(‘name‘)
def __delattr__(self, item):
print(‘del obj.name 我执行‘)
self.__dict__.pop(‘name‘)
s = A(‘wangba‘)
s.__dict__[‘age‘] = 25
# print(s.__dict__)
# print(s.__dict__.get(‘age‘))
# del s.__dict__[‘name‘]
# print(s.__dict__)
del s.name
print(s.__dict__)
原文地址:https://www.cnblogs.com/yuexijun/p/10336422.html
时间: 2024-10-13 00:23:28