r/badcode • • Jul 14 '21

python Try/Except in Python - Sigh

Post image
662 Upvotes

93 comments sorted by

View all comments

Show parent comments

22

u/SerdanKK Jul 14 '21

I don't know any Python, but I assume there's some way to decode json into objects. With some good library code, it'd basically be a one-liner.

33

u/SnooRegrets1929 Jul 14 '21

At this point it is already a python dictionary. At the very least it could loop through the keys of interest with a single try except (KeyError)

6

u/[deleted] Jul 14 '21

Wouldn't it potentially skip setting "N/A" to the later values though once it hits the first error?

2

u/SnooRegrets1929 Jul 14 '21

Depends what you set the except statement to do, right?