反射

class BlackMedium:
feture="Ugly"
def __init__(self,name,addr):
self.name=name
self.addr=addr
def sell_hourse(self):
print("[%s]正在买房子"%self.name)
def rent_hourse(self):
print("[%s]正在租房子"%self)
b1=BlackMedium("完成置地","天露园")

b=hasattr(b1,"name")

print(b1)
print(getattr(b1,"name"))
fun=getattr(b1,"rent_hourse")

fun()
setattr(b1,"sb","limgda")
print(b1.__dict__)
delattr(b1,"name")
print(b1.__dict__)
原文地址:https://www.cnblogs.com/zypfzw/p/9142057.html