+-

我是 Python的新手,我正在尝试基本上创建一个哈希表,检查一个键是否指向表中的值,如果没有,则将其初始化为空数组.我的代码的违规部分是这一行:
converted_comments[submission.id] = converted_comments.get(submission.id, default=0)
我收到错误:
TypeError: get() takes no keyword arguments
但是在文档(以及各种示例代码)中,我可以看到它确实采用了一个默认参数:
https://docs.python.org/2/library/stdtypes.html#dict.get
http://www.tutorialspoint.com/python/dictionary_get.htm
Following is the syntax for get() method:
dict.get(key, default=None)
在堆栈上没有任何关于这个,所以我认为这是一个初学者的错误?
最佳答案
错误消息表明get不接受任何关键字参数,但是您提供的默认值为0
converted_comments[submission.id] = converted_comments.get(submission.id, 0)
点击查看更多相关文章
转载注明原文:python – TypeError:get()不带关键字参数 - 乐贴网