I do this error handling a lot, is there a shorter way of writing this try except block ?
try:
config = item['asset'][0]['config']
except:
config = 'None'
like a pythonic oneliner maybe ?
I do this error handling a lot, is there a shorter way of writing this try except block ?
try:
config = item['asset'][0]['config']
except:
config = 'None'
like a pythonic oneliner maybe ?
Why don't you just write a method for it so you can call it whenever you need?
def validate_item(item):
try:
config_letter = item['asset'][0]['config']
except:
config_letter = 'None'
Obviously this is just a rough outline so you can reformat the params however you need.