Hacker News new | past | comments | ask | show | jobs | submit login

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



try/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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: