Original Translation
47
The context manager's :meth:`__enter__` method is invoked.
48
If a target was included in the :keyword:`with` statement, the return value from :meth:`__enter__` is assigned to it.
49
The :keyword:`with` statement guarantees that if the :meth:`__enter__` method returns without an error, then :meth:`__exit__` will always be called. Thus, if an error occurs during the assignment to the target list, it will be treated the same as an error occurring within the suite would be. See step 6 below.
50
The suite is executed.
51
The context manager's :meth:`__exit__` method is invoked. If an exception caused the suite to be exited, its type, value, and traceback are passed as arguments to :meth:`__exit__`. Otherwise, three :const:`None` arguments are supplied.
52
If the suite was exited due to an exception, and the return value from the :meth:`__exit__` method was false, the exception is reraised. If the return value was true, the exception is suppressed, and execution continues with the statement following the :keyword:`with` statement.
53
If the suite was exited for any reason other than an exception, the return value from :meth:`__exit__` is ignored, and execution proceeds at the normal location for the kind of exit that was taken.
54
With more than one item, the context managers are processed as if multiple :keyword:`with` statements were nested::
55
with A() as a, B() as b: suite
56
is equivalent to ::