Bel*_*lda 5 python dictionary python-2.7
我迷失在这里,Python 2.7,我有一本字典mt,我使用的get()方法,文档说:
get(key[, default])如果key在字典中,则返回key的值,否则返回default.如果未给出default,则默认为None,因此此方法永远不会引发aKeyError.
但我还是得到了
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,有时没有钥匙.
所以我把问题解决了.在此代码实施之前,有一个
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)
并重新加载应用程序一切都很好,没有问题.