0 votes
1 view
in Python by (47.7k 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 (107k 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

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...