Python说我向我的函数传递了太多参数?

Abe*_*ler 2 python python-2.7

我有一些python代码包含如下所示的单元测试:

class SunCalcTestCases(unittest.TestCase):
    """Tests for `suncalc.py`."""
    def near(val1, val2):
        return abs(val1 - val2) < (margin or 1E-15)

    def test_getPositions(self):
        """Get sun positions correctly"""
        sunPos = suncalc.getPosition(self.date, self.lat, self.lng)
        az = sunPos["azimuth"]
        res = self.near(az, -2.5003175907168385) 
Run Code Online (Sandbox Code Playgroud)

但是当我运行这个时,我得到错误:

Traceback (most recent call last):
  File "test.py", line 64, in test_getPositions
    res = self.near(az, -2.5003175907168385)
TypeError: near() takes exactly 2 arguments (3 given)
Run Code Online (Sandbox Code Playgroud)

我是python的新手,所以我很抱歉,如果我在这里遗漏了一些东西,但据我所知,我在调用函数时只传递了两个参数: self.near(az, -2.5003175907168385)

谁能告诉我为什么它认为我传递了3个参数?

Lit*_*leQ 5

你忘了传递selfnear功能

def near(self, val1, val2):

@classmethod和@staticmethod对初学者的意义?

Python中的@staticmethod和@classmethod有什么区别?

  • @AbeMiessler [参考](http://stackoverflow.com/questions/2709821/what-is-the-purpose-of-self-in-python) (3认同)