Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Decimal context
#1
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?
Reply
#2
Do __enter__ and __exit__ methods make sense for your classes? If so, you can use a context manager.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Context-sensitive delimiter ZZTurn 9 1,392 May-16-2023, 07:31 AM
Last Post: Gribouillis
  How does open context manager work? deanhystad 7 1,263 Nov-08-2022, 02:45 PM
Last Post: deanhystad
  TextIOWrapper.tell() with Python 3.6.9 in context of 0D/0A fschaef 0 2,040 Mar-29-2020, 09:18 AM
Last Post: fschaef
  testing for Decimal w/o importing decimal every time Skaperen 7 4,362 May-06-2019, 10:23 PM
Last Post: Skaperen
  Smtplib: What does context argument means? Pythenx 1 3,049 Mar-27-2019, 06:25 PM
Last Post: nilamo
  Dealing with multiple context managers heras 5 4,600 Nov-16-2018, 09:01 AM
Last Post: DeaD_EyE
  Context Manager (with) wyattbiker 3 3,724 Jul-23-2018, 03:19 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020