简体   繁体   中英

given a list of strings in python

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?

Define your function as

def changeme(self,listOne, lisrTwo, listThree, listFour, listfive):

This will make the function accessible to instance variables outside the class

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM