
# 使用__slots__限制类动态添加的实例属性

# 实例属性是优于类属性的
class Student(object):
    __slots__ = ('name','age','func')

def func():
    print('test')

# Student.name = 'zookfish'
# Student.age = 27
Student.sex = 'man'
# Student.func = func
s = Student()
s.func = func
s.name = 'name'
s.age = 'age'
# s.tec = 'tec'
print(s.func(),s.name,s.age,s.sex)
2d6f9eef1744f4c3b93383f89a74e1754bbc44c8
class Student(object):
    __slots__ = 'name', 'age', 'func'


<mask token>

class Student(object):
    __slots__ = 'name', 'age', 'func'


def func():
    print('test')


<mask token>

class Student(object):
    __slots__ = 'name', 'age', 'func'


def func():
    print('test')


<mask token>
print(s.func(), s.name, s.age, s.sex)

class Student(object):
    __slots__ = 'name', 'age', 'func'


def func():
    print('test')


Student.sex = 'man'
s = Student()
s.func = func
s.name = 'name'
s.age = 'age'
print(s.func(), s.name, s.age, s.sex)


# 使用__slots__限制类动态添加的实例属性

# 实例属性是优于类属性的
class Student(object):
    __slots__ = ('name','age','func')

def func():
    print('test')

# Student.name = 'zookfish'
# Student.age = 27
Student.sex = 'man'
# Student.func = func
s = Student()
s.func = func
s.name = 'name'
s.age = 'age'
# s.tec = 'tec'
print(s.func(),s.name,s.age,s.sex)