Python dict.get()引发了KeyError

Bel*_*lda 5 python dictionary python-2.7

我迷失在这里,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,有时没有钥匙.

Bel*_*lda 7

所以我把问题解决了.在此代码实施之前,有一个

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

问题是旧版本中有.pyc文件,但堆栈跟踪正在加载实际代码.跑完之后

find . -name "*.pyc" -exec rm -rf {} \;
Run Code Online (Sandbox Code Playgroud)

并重新加载应用程序一切都很好,没有问题.