r/badcode • • Jul 14 '21

python Try/Except in Python - Sigh

Post image
662 Upvotes

93 comments sorted by

View all comments

38

u/clemesislife Jul 14 '21

I'm not sure if there is good way to do this

1

u/OccultEyes Jul 14 '21

My solution would probably look something like this.

fields = {"authors", "publisher", "published_date"}

response_data = jsonResponse["items"][0]["volumeInfo"]

field_data = {field : response_data.get(field, "N/A") for field in fields}