I have multiple try/except blocks in a program where I am analyzing a dictionary input from another module. I basically use the try/except (EAFP) to check if a certain key is in the input (otherwise, I want to raise an error).
I was wondering if there is a more general approach. Instead of
try: xyz = a['some_key'] except: print_error("Key 'some_key' was not defined")
dozens of times, if there was a way to do something like
try: xyz = a['some_key'] xyz2 = a['some_key2'] ... except: print_error("The key(s) that were not included were some_key, some_key2")