Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (47.6k points)

In my python program I am getting this error:

KeyError: 'variablename'

From this code:

path = meta_entry['path'].strip('/'),

Can anyone please explain why this is happening?

1 Answer

0 votes
by (106k points)
edited by

The general reason for a KeyError means the key doesn't exist. 

exception KeyError:-

This exception error raised when a mapping (dictionary) key is not found in the set of existing keys.

For example:

>>> mydict = {'a':'1','b':'2'} 

>>> mydict['a'] '1' 

>>> mydict['c'] 

Traceback (most recent call last): 

  File "<stdin>", line 1, in <module> 

KeyError: 'c' 

To know more about this you can have a look at the following video tutorial:-

Related questions

Browse Categories

...