Python调用基类的方法

# 基类
class A(object):
    def show(self):
        print('base show')

# 派生类
class B(A):
    def show(self):
        print('derived show')
  
obj = B()
obj.show()
# 调用基类的show
obj.__class__ = A
obj.show()
# 调用派生类的show
obj.__class__ = B
obj.show()

打印日志:

derived show
base show
derived show

 

你可能感兴趣的:(Python)