On this page
decimal.setcontext
Prev: decimal.Rounded | Up: decimal | Next: decimal.Subnormal
Rel: decimal.Clamped, decimal.Context, decimal.ConversionSyntax, decimal.Decimal
Ref: docs.python.org — decimal.setcontext
Tags: #public #python3 #stdlib #decimal
Import
import decimal
from decimal import setcontext
Signature & Overview
decimal.setcontext(context, /)
Set a new default context.
Usage
from decimal import Context, getcontext, setcontext
old = getcontext()
setcontext(Context(prec=10))
try:
assert getcontext().prec == 10
finally:
setcontext(old)
Gotchas
- Prefer
with localcontext(ctx):: Guarantees restoration even if an exception occurs.
REPL Inspect
from decimal import setcontext
help(setcontext)
Linked from
Related notes
- tuts/python3/stdlib_module/decimal/Rounded Linked here; links to this page; shared tags: #decimal, #stdlib
- tuts/python3/stdlib_module/decimal/Subnormal Linked here; links to this page; shared tags: #decimal, #stdlib
- tuts/python3/stdlib_module/decimal/Clamped Linked here; shared tags: #decimal, #stdlib
- tuts/python3/stdlib_module/decimal/Context Linked here; shared tags: #decimal, #stdlib
- tuts/python3/stdlib_module/decimal/ConversionSyntax Linked here; shared tags: #decimal, #stdlib
- tuts/python3/stdlib_module/decimal/Decimal Linked here; shared tags: #decimal, #stdlib
- tuts/python3/stdlib_module/decimal links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/decimal/DecimalException shared tags: #decimal, #stdlib
- tuts/python3/stdlib_module/decimal/DecimalTuple shared tags: #decimal, #stdlib
- tuts/python3/stdlib_module/decimal/DivisionByZero shared tags: #decimal, #stdlib