class A: |
def __init__( self ): |
print ( 'A init' ) |
self .a1 = 'a1' |
def __get__( self , instance, owner): |
print ( 'A.__get__' , self ,instance,owner) |
return self |
def __set__( self , instance, value): |
print ( 'A.__set__' , self ,instance,value) |
class B: |
x = A() |
def __init__( self ): |
print ( 'B.init' ) |
# self.x = 100 #触发了类的set描述器,相当于操作类属性 |
# self.x = A() |
# print(B.x) |
# print() |
# print(B.x.a1) |
# print() |
b = B() |
# print() |
# print(B.x) |
# print() |
# print(b.x.a1) |
b.x = 600 |
print (b.x) |
print (b.__dict__) |
# B.x = 500 |
print (B.__dict__) |