Python with_metaclass 继承测试

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/brook0344/article/details/90695918
#!/usr/bin/python
from six import with_metaclass

class A(type):
	def TestA(self):
		print('TestA')
		
class B(object):
	def TestB(self):
		print('TestB')
		
class C(with_metaclass(A,B)):
	def TestC(self):
		print('TestC')
    

c=C()
c.TestC()
c.TestB()
c.TestA()

输出结果:

TestC
TestB
Traceback (most recent call last):
  File "/tmp/516425337/main.py", line 20, in <module>
    c.TestA()
AttributeError: 'C' object has no attribute 'TestA'

exit status 1

展开阅读全文

没有更多推荐了,返回首页