【发布时间】:2015-01-20 18:21:45
【问题描述】:
今天早上我提出了一个奇怪的理想。众所周知,在 python 中,一切都是对象,包括类和函数。
不要问我为什么要这样做。这是一个玩python的实验。我知道它是从实例继承的。
我们试试吧:
kk=dict()
print dir(dict)
print dir(kk)
output of them are same
class yy(dict): pass ---ok
class zz(kk) : fail ---error
TypeError: Error when calling the metaclass bases
dict expected at most 1 arguments, got 3
谁能深入解释我为什么收到此错误消息?
再次。如果可能,请解释一下python是如何输出这个错误信息的?
【问题讨论】:
-
zz正在尝试从 instance 继承。对于fail上的NameError,它甚至还远远不够。 -
查看python文档元类是如何工作的。
标签: python class inheritance metaclass