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)
为什么在启动这段代码后,我会得到这个错误:
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'
我正在使用 Python 3。
最佳答案
你的意思可能是:
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)
注意括号的使用:key1 = Keys()
关于python - 缺少 1 个必需的位置参数 : 'key' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30694097/