[root@localhost /]# cat zlg.py
#!/bin/python
class A(object):
def run(self):
print("aaaaaaaaaaaaaaaaaa")
class B(A):
def run(self):
print("bbbbbbbbbbbbbbbbbb")
obj = B()
obj.__class__ = A
obj.run()
class A(object):
def __init__(self,a,b):
self.__a = a
self.__b = b
def show(self):
print("a=",self.__a,"b=",self.__b)
def __call__(self, num):
print("call:",num + self.__a)
a = A(5,10)
a.show()
a(20)
class B(object):
def __init__(self):
print("B init")
def run(self):
print("B run func")
class A(object):
def run(self):
print("A run func")
def __new__(cls, a):
print("new",a)
if a>10:
return super(A,cls).__new__(cls)
return B()
def __init__(self,a):
print("init",a)
a1 = A(5)
a1.run()
a2 = A(20)
class A(object):
def __init__(self,a,b):
self.a1 = a
self.b1 = b
print("hahahahahahahahahaha")
def myfunc(self):
print("myfunc")
def __getattr__(self, item):
return self.myfunc
a1 = A(10,20)
a1.fn1()
a1.fn2()
a1.fn3()
[root@localhost /]#
阅读(1433) | 评论(0) | 转发(0) |