For the error:
TypeError: takes exactly 1 argument (2 given)
With the following class method:
def extractAll(tag):
...
and calling it:
e.extractAll("th")
The error seems very odd when I'm giving it 1 argument, the method should take only 1 argument, but it's saying I'm not giving it 1 argument....I know the problem can be fixed by adding self
into the method prototype but I wanted to know the reasoning behind the error.
Am I getting it because the act of calling it via e.
extractAll("th") also passes in self
as an argument? And if so, by removing the self
in the call, would I be making it some kind of class method that can be called like Extractor.extractAll("th")
?
The call
for a regular method
extractAll()
is indeed equivalent toThese two calls are treated the same in all regards, including the error messages you get.
If you don't need to pass the instance to a method, you can use a
staticmethod
:which can be called as
e.extractAll("th")
. But I wonder why this is a method on a class at all if you don't need to access any instance.