调用元类基础时出错:function()参数1必须是代码,而不是str [英] Error when calling the metaclass bases: function() argument 1 must be code, not str
本文介绍了调用元类基础时出错:function()参数1必须是代码,而不是str的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图子类化线程。条件今天早些时候,但它没有工作。这里是Python解释器的输出,当我尝试子类threading.Condition类:
I tried to subclass threading.Condition earlier today but it didn't work out. Here is the output of the Python interpreter when I try to subclass the threading.Condition class:
>>> 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
b $ b
有人可以解释这个错误吗?谢谢!
Can someone explain this error? Thanks!
推荐答案
你得到了那个异常,因为尽管它的类名,条件
是一个函数,您不能子类化函数。
You're getting that exception because, despite its class-like name, threading.Condition
is a function, and you cannot subclass functions.
>>> type(threading.Condition)
<type 'function'>
这个非常有用的错误消息在Python的bugtracker ,但它已被标记为不会修复。
This not-very-helpful error message has been raised on the Python bugtracker, but it has been marked "won't fix."
这篇关于调用元类基础时出错:function()参数1必须是代码,而不是str的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文