Decimal context - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Decimal context (/thread-36914.html) |
Decimal context - stevendaprano - Apr-11-2022 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? RE: Decimal context - deanhystad - Apr-11-2022 Do __enter__ and __exit__ methods make sense for your classes? If so, you can use a context manager. |