First page Back Continue Last page Overview Graphics
Context Objects
Decimal objects have a per-thread context object.
Controls various things:
- # of digits of precision
- Rounding rules
- Whether to raise exceptions or set flags
- Access to flags that were raised
decimal.getcontext(), or supply with operation
Normally needed only for fairly advanced things.
Notes:
The decimal module also creates a per-thread context object. This controls a several things: the number of digits of precision, the rounding rules, whether to throw exceptions or “raise flags”. It provide a place to go to see if the flags have been raised. There are a few other things also.
The per-thread instance can be accessed by decimal.getcontext(), or a context object can be supplied along with most decimal operations. The context is per thread so that different libraries can avoid interfering with each other.
The context object is really needed only for some pretty advanced things. Normally, just ignore it.