我今天早些时候尝试对 threading.Condition 进行子类化,但没有成功。这是我尝试继承 threading.Condition 类时 Python 解释器的输出:
>>> import threading
>>> class ThisWontWork(threading.Condition):
... pass
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: Error when calling the metaclass bases
function() argument 1 must be code, not str
有人可以解释这个错误吗?谢谢!
最佳答案
你得到这个异常是因为,尽管它的名字类似于类,threading.Condition
是一个函数,你不能子类化函数。
>>> type(threading.Condition)
<type 'function'>
这个不太有用的错误消息是 raised on the Python bugtracker ,但它已被标记为“不会修复”。
关于python - 调用元类库时出错 : function() argument 1 must be code, not str,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2231427/