__dict__:实例化类时将实例属性分配到__dict__
__slots__:阻止实例分配属性到__dict__
class Base(object):
__slots__ = ['y', 'x']
def __init__(self):
self.y = 'aa'
self.x = 'xx'
b = Base()
print b.__dict__ #抛错
print b.y
b.x = 30
print b.x
__dict__:实例化类时将实例属性分配到__dict__
__slots__:阻止实例分配属性到__dict__
class Base(object):
__slots__ = ['y', 'x']
def __init__(self):
self.y = 'aa'
self.x = 'xx'
b = Base()
print b.__dict__ #抛错
print b.y
b.x = 30
print b.x