Get rid of python's KeyError

Introduction

Touching python

"KeyError: None"

I got the error. Make a note of the cause and correction method. (Corrected to what you received in the comments.)

Cause

You have specified the keys foo ['bar'] and bar, but it is probable that the keys do not exist.

How to fix

Since there is a possibility of a typo, review the key if you know the key yourself or if the key is described in the program. If not, insert the following code in the appropriate position.

python


...
print(foo.keys())
...#An error occurs here

Correct the ['bar'] part appropriately.

Recommended Posts

Get rid of python's KeyError
Get rid of slow scp -pr
Get rid of DICOM images in Python
[Python] Get rid of dating with regular expressions
manage to get rid of heavy pyls in vim-lsp
How to get rid of server custom emoji in message.content
Get the number of digits
Get rid of dirty data with Python and regular expressions
Get rid of garbled Japanese strings when going through FBX
Python techniques for those who want to get rid of beginners
I'll get rid of every single imperial system from the world!
Get the number of views of Qiita
I get a KeyError in pyclustering.xmeans
Get absolute path of running process
Make full use of Python's str.format
Get the attributes of an object
Get the first element of queryset
Get the number of Youtube subscribers