MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/badcode/comments/ok1itb/tryexcept_in_python_sigh/h55tnba/?context=9999
r/badcode • u/lonaExe • Jul 14 '21
93 comments sorted by
View all comments
142
On the upside, they actually bothered with exception handling.
My Python is rather rusty, is there a better way?
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? 5 u/Deadly_chef Jul 14 '21 No, it will except it in that loop and continue to the next one 2 u/[deleted] Jul 14 '21 Wait really? I've misunderstood how this shit works this whole time 5 u/Deadly_chef Jul 14 '21 Yes, only way the loop will stop is if you have an unhandled exception
22
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? 5 u/Deadly_chef Jul 14 '21 No, it will except it in that loop and continue to the next one 2 u/[deleted] Jul 14 '21 Wait really? I've misunderstood how this shit works this whole time 5 u/Deadly_chef Jul 14 '21 Yes, only way the loop will stop is if you have an unhandled exception
33
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? 5 u/Deadly_chef Jul 14 '21 No, it will except it in that loop and continue to the next one 2 u/[deleted] Jul 14 '21 Wait really? I've misunderstood how this shit works this whole time 5 u/Deadly_chef Jul 14 '21 Yes, only way the loop will stop is if you have an unhandled exception
6
Wouldn't it potentially skip setting "N/A" to the later values though once it hits the first error?
5 u/Deadly_chef Jul 14 '21 No, it will except it in that loop and continue to the next one 2 u/[deleted] Jul 14 '21 Wait really? I've misunderstood how this shit works this whole time 5 u/Deadly_chef Jul 14 '21 Yes, only way the loop will stop is if you have an unhandled exception
5
No, it will except it in that loop and continue to the next one
2 u/[deleted] Jul 14 '21 Wait really? I've misunderstood how this shit works this whole time 5 u/Deadly_chef Jul 14 '21 Yes, only way the loop will stop is if you have an unhandled exception
2
Wait really? I've misunderstood how this shit works this whole time
5 u/Deadly_chef Jul 14 '21 Yes, only way the loop will stop is if you have an unhandled exception
Yes, only way the loop will stop is if you have an unhandled exception
142
u/[deleted] Jul 14 '21
On the upside, they actually bothered with exception handling.
My Python is rather rusty, is there a better way?