Return a context manager that will set the current context for the active thread to a copy of ctx on entry to the with-statement and restore the previous context when exiting the with-statement. If no context is specified, a copy of the current context is used. The kwargs argument is used to set the attributes of the new context.
decimal.localcontext(ctx=None, \*\*kwargs)
from decimal import localcontext
with localcontext() as ctx:
ctx.prec = 42 Perform a high precision calculation
s = calculate_something()
s = +s Round the final result back to the default precision
from decimal import localcontext
with localcontext(prec=42) as ctx:
s = calculate_something()
s = +s