Python Forum

Full Version: Decimal context
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
The decimal module has a current context which defines the settings used for decimal calculations.

Let's say I have two classes, B and E. In the B class I want all my decimal calculations to use the BasicContext, and in my E class I want them all to use ExtendedContext.

Is it possible to define a context for each class, or the whole module, so that I don't have to manually set the context in every method?
Do __enter__ and __exit__ methods make sense for your classes? If so, you can use a context manager.