Python - TypeError: float object is not callable error

前端 未结 1 534
醉梦人生
醉梦人生 2021-01-26 19:25

Have got the following code so far:

class beam(object):

    def __init__(self, E, I, L):
         self.E = E  
         self.I = I  
         self.L = L  
              


        
相关标签:
1条回答
  • 2021-01-26 20:16

    The only way that this could happen is if you pass a float to derivative() in place of a function:

    >>> scipy.misc.derivative(1.0, 1.0)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/usr/lib64/python2.7/site-packages/scipy/misc/common.py", line 195, in derivative
        val += weights[k]*func(x0+(k-ho)*dx,*args)
    TypeError: 'float' object is not callable
    

    Are you absolutely sure that your code is as posted? Most likely your code is actually calling self.getTotalDeflection and therefore passing its return value (a float) to derivative(), e.g. your code might be:

    return scipy.misc.derivative(self.getTotalDeflection(x), x)
    

    or similar, when it should really be as you have posted, i.e.

    return scipy.misc.derivative(self.getTotalDeflection, x)
    
    0 讨论(0)
提交回复
热议问题