python: function takes exactly 1 argument (2 given)

前端 未结 1 1851
天涯浪人
天涯浪人 2021-01-04 21:28

I have this method in a class

class CatList:

    lista = codecs.open(\'googlecat.txt\', \'r\', encoding=\'utf-8\').read()
    soup = BeautifulSoup(lista)            


        
相关标签:
1条回答
  • 2021-01-04 22:01

    You forgot the self argument.

    You need to change this line:

    def parseList(tag):
    

    with:

    def parseList(self, tag):
    

    You also got a global name error, since you're trying to access parseList without self.
    While you should to do something like:

    self.parseList(item)
    

    inside your method.

    To be specific, you need to do that in two lines of your code:

     return [self.parseList(item)
    

    and

     return (tag.contents[0].string.strip(), self.parseList(tag.ul))
    
    0 讨论(0)
提交回复
热议问题