相关疑难解决方法(0)

Python dict.get()引发了KeyError

我迷失在这里,Python 2.7,我有一本字典mt,我使用的get()方法,文档说:

get(key[, default])如果key在字典中,则返回key的值,否则返回default.如果未给出default,则默认为None,因此此方法永远不会引发a KeyError.

但我还是得到了

 File "/home/ubuntu/subscription-workers/commands/dr/rebilling.py", line 48, in rebill
    if mt.get('is_rebill', 0) == 1:
 KeyError: 'is_rebill'
Run Code Online (Sandbox Code Playgroud)

有什么想法吗?

mt是正常的dict,有时没有钥匙.

python dictionary python-2.7

5
推荐指数
1
解决办法
3826
查看次数

标签 统计

dictionary ×1

python ×1

python-2.7 ×1