缺少1个必需的位置参数:'key'

时间:2015-06-07 13:31:09

标签: python oop python-3.x

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'

为什么在启动此代码后出现错误

// main()'s pseudo arguments.
#define AT_PAGESZ 6
argv:
        .word   name
        .word   0                       // End of argv.
        .word   0                       // End of envp.
        // Auxv
        .word   AT_PAGESZ
        .word   4096                    // Page size.
        .word   0

我使用python3

2 个答案:

答案 0 :(得分:2)

你可能意味着:

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

答案 1 :(得分:0)

你错过了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)