I really do want to understand this documentation:
from `pydoc try`
The ``try`` statement
*********************
The ``try`` statement specifies exception handlers and/or cleanup code
for a group of statements:
try_stmt ::= try1_stmt | try2_stmt
try1_stmt ::= "try" ":" suite
("except" [expression ["as" target]] ":" suite)+
["else" ":" suite]
["finally" ":" suite]
try2_stmt ::= "try" ":" suite
"finally" ":" suite
So what exactly does the first line mean?
try_stmt ::= try1_stmt | try2_stmt
.
It's a bit confusing as I know how to implement very simple try statements like this;
try:
import io
print("importing io")
except ImportError:
print("nothing to import")
foo = None
try:
import somefunctionthatdoesnotexist
print("importing ...")
except ImportError:
print("nothing to import")
foo = None