Takes exactly 3 arguments (4 given)

前端 未结 2 2028
轮回少年
轮回少年 2020-12-19 21:02

i\'m refactoring code in order to add object orientation and am just testing the code.

pattern = r\"((([01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])[ (\\[]?(\\.|dot)         


        
相关标签:
2条回答
  • 2020-12-19 21:41

    You are giving self.getip() four arguments because Python automatically adds in first self argument for bound methods. The expression:

    self.getip(self, pattern, line)
    

    results in:

    getip(self, self, pattern, line)
    

    which is four arguments.

    Don't pass in self again:

    self.ip = self.getip(pattern, line)
    

    The very act of looking up the method on the instance (via self.getip) binds the method to handle that first argument for you.

    0 讨论(0)
  • 2020-12-19 21:47

    When calling an instance method, you don't pass the instance explicitly

    ie.

    self.ip = self.getip(pattern, line)
    
    0 讨论(0)
提交回复
热议问题