missing 1 required positional argument: 'key'

22.4k Views Asked by At
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.

2

There are 2 best solutions below

0
On BEST ANSWER

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()

0
On

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)