Skip to content

Instantly share code, notes, and snippets.

@scooby
Created March 11, 2020 22:39
Show Gist options
  • Save scooby/2063bbb6dfab8766d3aff55a7eba516f to your computer and use it in GitHub Desktop.
Save scooby/2063bbb6dfab8766d3aff55a7eba516f to your computer and use it in GitHub Desktop.
A straightforward way to handle missing keys.
try:
val = my_dict[key]
except KeyError:
handle_missing_value(key)
else:
normal_logic(key, val)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment