Answer by user2622016 for Why does using `or` within an except clause not...
You should use a n-tuple of types instead of a logical expression (which just returns the first non-false element):def with_or_raise(exc): try: raise exc() except (IndexError,KeyError): print('Got ya!')
View ArticleAnswer by deceze for Why does using `or` within an except clause not cause a...
In except e, e can be any valid Python expression:try1_stmt ::= "try"":" suite ("except" [expression ["as" identifier]] ":" suite)+ ...[..] For an except clause with an expression, that expression is...
View ArticleWhy does using `or` within an except clause not cause a SyntaxError? Is there...
At work, I stumbled upon an except clause with an or operator:try: # Do something.except IndexError or KeyError: # ErrorHandlingI know the exception classes should be passed as a tuple, but it bugged...
View Article