# coding: utf-8
class A(object):
x = 1
def __init__(self):
self.y = 2
a = A()
print a.__dict__
print(a.x, a.y)
a.x = 10
a.y = 10
print(a.x, a.y)
class B(object):
__slots__ = ('x', 'y')
x = 1
z = 2
def __init__(self):
self.y = 3
# self.m = 5 # 这个是不成功的
b = B()
# print(b.__dict__)
print(b.x, b.z, b.y)
# b.x = 10
# b.z = 10
b.y = 10
print(b.y)
class C(object):
__slots__ = ('x', 'z')
x = 1
def __setattr__(self, name, val):
if name in C.__slots__:
object.__setattr__(self, name, val)
def __getattr__(self, name):
return "Value of %s" % name
c = C()
print(c.__dict__)
print(c.x)
print(c.y)
# c.x = 10
c.z = 10
c.y = 10
print(c.z, c.y)
c.z = 100
print(c.z)
{'y': 2}
(1, 2)
(10, 10)
(1, 2, 3)
10
Value of __dict__
1
Value of y
(10, 'Value of y')
100
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有