all Python 3Numbers & mathfunction
decimal.setcontext()
decimal
Replace the current Decimal context wholesale with the given one — useful when you have a prebuilt Context rather than tweaking fields one by one.
Syntax
decimal.setcontext(ctx)
Only the calling thread's context changes — other threads keep their own, and restoring the previous one after setcontext is your job. For a temporary setting, with decimal.localcontext(...) is safer because it puts the old context back for you; also note that the Context object you pass is kept as is, so mutating its fields later immediately affects every subsequent operation.
Examples
import decimal
decimal.setcontext(decimal.Context(prec=10))
decimal.getcontext().prec # → 10
decimal.Decimal(1) / decimal.Decimal(3) # → Decimal('0.3333333333')
See also
Open in the full glossarydocs.python.orgReport an inaccuracy