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
  [PROBLEM] Removing IDLE from context menu WebSpider 1 1,677 Sep-28-2023, 03:35 PM
Last Post: deanhystad
  with open context inside of a recursive function billykid999 1 1,923 May-23-2023, 02:37 AM
Last Post: deanhystad
  Context-sensitive delimiter ZZTurn 9 4,424 May-16-2023, 07:31 AM
Last Post: Gribouillis
  How does open context manager work? deanhystad 7 3,855 Nov-08-2022, 02:45 PM
Last Post: deanhystad
  TextIOWrapper.tell() with Python 3.6.9 in context of 0D/0A fschaef 0 3,148 Mar-29-2020, 09:18 AM
Last Post: fschaef
  Time execution of a "for loop" with zip different in 2 equivalent context sebastien 1 2,871 Oct-11-2019, 11:07 AM
Last Post: sebastien
  Is it OK to use a context manager to simplify attribute access? nholtz 0 2,863 Jun-11-2019, 01:19 AM
Last Post: nholtz
  testing for Decimal w/o importing decimal every time Skaperen 7 7,183 May-06-2019, 10:23 PM
Last Post: Skaperen
  Smtplib: What does context argument means? Pythenx 1 4,402 Mar-27-2019, 06:25 PM
Last Post: nilamo
  eval lambda function with restricted context Olivier 7 8,232 Mar-04-2019, 10:45 PM
Last Post: Olivier

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020
This forum uses Lukasz Tkacz MyBB addons.
Forum use Krzysztof "Supryk" Supryczynski addons.