Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
KeyError and TypeError
#1
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.
Reply
#2
"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.
deneme2 likes this post
Reply
#3
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
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020