在werkzeug中有这样的定义:
class Local(object):
__slots__ = ('__storage__', '__ident_func__')
def __init__(self):
object.__setattr__(self, '__storage__', {})
object.__setattr__(self, '__ident_func__', get_ident)
此处的__init__方法里,使用self.__storage__ = {}
的话是否效果一样呢?
The effect is actually the same.
For example
object.a = 1
最终也是调用self.__setattr__('a', 1)
;But when you override the __setattr__ method of the parent class (object), you can add some rules you define, such as: