Are there any other uses for Python\'s \"from\" keyword aside from import
statements?
With the finalization of PEP 3134, the from
keyword can be used when an exception is generated (raise
) as a consequence of catching an exception in a try-except
block.
try:
except as e:
raise from e
The keyword from
allows to keep track of the caught exception e
in the new excaption raised. The exception e
will be stored in the attribute __cause__
of the new exception.