为什么我会收到此错误“TypeError:'int'对象不可调用”?

时间:2016-10-15 05:34:03

标签: python python-2.7

def diameter(Points):
    '''Given a list of 2d points, returns the pair that's farthest apart.'''
    diam,pair = max([((p[0]-q[0])**2 + (p[1]-q[1])**2, (p,q))
                     for p,q in rotatingCalipers(Points)])
    return pair


n=int(input())

a=[]

max=0

for i in xrange(n):
    m,n=map(int,raw_input().split())
    a.append((m,n))
    diameter(a)

回溯

Traceback (most recent call last):
  File "geocheat1.py", line 56, in <module>
    diameter(a)
  File "geocheat1.py", line 43, in diameter
    for p,q in rotatingCalipers(Points)])
TypeError: 'int' object is not callable

1 个答案:

答案 0 :(得分:1)

从Traceback中可以清楚地看到你试图调用int对象,所以rotatingCalipers可能在你的代码中被声明为整数。

请参阅此示例,您将了解错误

In [1]: a = (1,2,3)
In [2]: list(a)
Out[1]: [1, 2, 3]
In [3]: list = 5
In [4]: list(a)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-20-61edcfee5862> in <module>()
----> 1 list(a)

TypeError: 'int' object is not callable