Reputation:
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
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
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