Python Forum
KeyError and TypeError - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: KeyError and TypeError (/thread-40518.html)



KeyError and TypeError - deneme2 - Aug-10-2023

Hello Friends,

When I use this one
        if "Corners." in matches["matchInfosFull"]:
            continue
it gives this error
Error:
KeyError: 'matchInfosFull'
When I use this second one:
        if "Corners." in matches.get("matchInfosFull"):
            continue
it gives this error
Error:
TypeError: argument of type 'NoneType' is not iterable
When I use this third one:
        if "Corners." in [matches.get("matchInfosFull")]:
            continue
it does not give any error but it does not apply any filter to the output with "if-continue" phrase

Anyone has an idea to solve it?
Thanks for your interest and time.


RE: KeyError and TypeError - deanhystad - Aug-10-2023

"matchInfosFull" is not in the matches dictionary. The way to solve it is only use keys that appear in the dictionary.

I suppose you could do this:
if "Corners." in matches.get("matchInfosFull", []):
    continue
This returns an empty list when matchInfosFull is not in matches.


RE: KeyError and TypeError - deneme2 - Aug-10-2023

Yep, thats it @deanhystad.
It worked out buddy, it solved.
Thank you, thanks a lot for your time. Clap

btw: your nickname reminds me tough scandinavian centre back players in the premier league