2 ms·
For me, the optional else on for loops isn't nearly as mentally destabilizing as the optional else on try-except blocks. An ex-employee used to love doing that:
by mdaniel 12y ago
For me, the optional else on for loops isn't nearly as mentally destabilizing as the optional else on try-except blocks. An ex-employee used to love doing that:
try:
None.doit()
except Exception as e:
logger.exception('Nope')
else:
# now what?
pass
- edavis 12y agotry/except/else used to throw me, but I've grown to like the idiom. All it means is the try clause didn't raise any exceptions. And a "finally" clause is ran whether an exception was raised or not.