“TypeError 'xxx' object is not callable"是什么意思?方法? [英] What does "TypeError 'xxx' object is not callable" means?
问题描述
作为 Python 的初级开发人员,我在控制台中多次看到此错误消息,但我并不完全理解它的含义.
As a starting developer in Python I've seen this error message many times appearing in my console but I don't fully understand what does it means.
谁能告诉我,一般来说,什么样的动作会产生这个错误?
Could anyone tell me, in a general way, what kind of action produces this error?
推荐答案
当您尝试使用 ()
调用一个不是 ()
的对象时会发生该错误a href="http://docs.python.org/2/reference/datamodel.html#object.__call__" rel="noreferrer">可调用.
可调用对象可以是函数或类(实现了__call__
方法).根据 Python 文档:
A callable object can be a function or a class (that implements __call__
method). According to Python Docs:
object.__call__(self[, args...]):当实例作为函数被调用"时调用
object.__call__(self[, args...]): Called when the instance is "called" as a function
例如:
x = 1
print x()
x
不是一个可调用的对象,但你试图调用它,就好像它是它一样.此示例产生错误:
x
is not a callable object, but you are trying to call it as if it were it. This example produces the error:
TypeError: 'int' object is not callable
<小时>
为了更好地了解什么是可调用对象在另一篇 SO 帖子中阅读此答案.
这篇关于“TypeError 'xxx' object is not callable"是什么意思?方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!