Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from decimal import Decimal, getcontext
- from types import TracebackType
- from typing import Optional
- class Precision:
- old_prec = 3
- new_prec = 3
- def __init__(self, precision: int) -> None:
- try:
- precision = round(precision)
- except Exception:
- raise TypeError
- if precision < 1:
- raise ValueError
- self.old_prec = getcontext().prec
- self.new_prec = precision
- def __enter__(self) -> None:
- #print("call __enter__")
- getcontext().prec = self.new_prec
- def __exit__(self, exc_type, exc_value, exc_tb) -> None:
- #print("call __exit__")
- getcontext().prec = self.old_prec
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement