I have the following code in python:
class CreateMap:
def changeme(listOne, lisrTwo, listThree, listFour, listfive):
if __name__ == "__main__":
createMap = CreateMap()
createMap.changeme(["oneItem", "secondItem"],[],[],[],[])
It gives me the following error:
TypeError: changeme() takes exactly 5 arguments (6 given)
As I understand, it recognize the first list as two list. How can I avoid it?
-
You would receive the exact same error if your first argument were null. The problem is that you're trying to call a static function as if it were a method (which passes the instance, createMap, as the first argument).stewSquared– stewSquared2014年11月30日 14:21:28 +00:00Commented Nov 30, 2014 at 14:21
2 Answers 2
Define your function as
def changeme(self,listOne, lisrTwo, listThree, listFour, listfive):
This will make the function accessible to instance variables outside the class
Comments
It's not recognizing the first list as two lists. You must use self as the first argument in your function, because explicit is better than implicit. The reasoning has been given here in detail. I'll quote some here.
First, it’s more obvious that you are using a method or instance attribute instead of a local variable. Reading self.x or self.meth() makes it absolutely clear that an instance variable or method is used even if you don’t know the class definition by heart.