Error: function() takes at least n arguments (n given)

后端 未结 1 879
-上瘾入骨i
-上瘾入骨i 2021-01-18 01:24

I\'m trying to use SymPy to take residues, in this case the cotangent function. I\'ve got an integrate() function:

import sympy as sy
import numpy as np

de         


        
1条回答
  •  囚心锁ツ
    2021-01-18 01:40

    When you get an error message that indicates Python can't count arguments, it's generally because the number of arguments you've passed is equal to the number of required arguments, but you're missing some required arguments and including some optional arguments. In this case, you have the following definition:

    def integrate(f, z, gamma, t, lower, upper, exact=True):
    

    and the following call:

    integrate(f, z, gamma, 0, 2*sy.pi, exact=True)
    

    If we line them up, we see

    def integrate(f, z, gamma, t, lower, upper, exact=True):
    
        integrate(f, z, gamma, 0, 2*sy.pi,      exact=True)
    

    that you're missing one of lower, upper, or t, but because you've supplied exact, the error reporting gets confused.

    Python 3 has a better error message for things like this:

    >>> def f(a, b=0): pass
    ... 
    >>> f(b=1)
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: f() missing 1 required positional argument: 'a'
    

    0 讨论(0)
提交回复
热议问题