1

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?

1
  • 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). Commented Nov 30, 2014 at 14:21

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.