DEV Community

Discussion on: 🐍 Beware of Python dict.get()

Collapse
 
dwd profile image
Dave Cridland

Checking the return value properly. Or, just going for it and catching exceptions:

try:
    price_from_extruct = data_from_extruct['offer']['amount']
except:
    price_from_extruct = 0  # If you really wanted to do this.

The thing is, I find exceptions a good way of handling complex and arbitrary error flows. If you don't have a good story for what to do, trying to avoid the exceptions is just causing more headaches later.