user3460489
user3460489

Reputation:

missing 1 required positional argument: 'key'

class Keys():
    def __init__(self):
        self.key_list = {1:"one", 2:"two", 3:"three"}
    def get_name(self, key):
       self.ddd = key

key1 = Keys
key1.get_name(1)

Why, after starting this code, do I get this error:

Traceback (most recent call last):
  File "class.py", line 8, in <module>
    key1.get_name(1)
TypeError: get_name() missing 1 required positional argument: 'key'

I am using Python 3.

Upvotes: 6

Views: 23911

Answers (2)

Padraic Cunningham
Padraic Cunningham

Reputation: 180441

You are missing the parens:

class Keys():
    def __init__(self):
        self.key_list = {1:"one", 2:"two", 3:"three"}
    def get_name(self, key):
       self.ddd = key

key1 = Keys() # <- missing parens
key1.get_name(1)

Upvotes: 0

AvidLearner
AvidLearner

Reputation: 4163

You probably meant:

class Keys():
    def __init__(self):
        self.key_list = {1:"one", 2:"two", 3:"three"}
    def get_name(self, key):
       self.ddd = key

key1 = Keys()
key1.get_name(1)

Note the use of parenthesis: key1 = Keys()

Upvotes: 5

Related Questions