summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2008-01-11 02:24:13 (GMT)
committerRaymond Hettinger <python@rcn.com>2008-01-11 02:24:13 (GMT)
commit097a1903035f9ee2efb1953306123f183124125d (patch)
tree1a60761457bdff8b022ae9d942cb1639cd959fd7 /Lib
parenta7d984e838d509e5ff41fd89be6aaa338a8b4834 (diff)
downloadcpython-097a1903035f9ee2efb1953306123f183124125d.zip
cpython-097a1903035f9ee2efb1953306123f183124125d.tar.gz
cpython-097a1903035f9ee2efb1953306123f183124125d.tar.bz2
Have Decimal.as_tuple return a named tuple.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/decimal.py8
1 files changed, 7 insertions, 1 deletions
diff --git a/Lib/decimal.py b/Lib/decimal.py
index 3ee078f..8b54821 100644
--- a/Lib/decimal.py
+++ b/Lib/decimal.py
@@ -136,6 +136,12 @@ __all__ = [
import copy as _copy
+try:
+ from collections import namedtuple as _namedtuple
+ DecimalTuple = _namedtuple('DecimalTuple', 'sign digits exponent')
+except ImportError:
+ DecimalTuple = lambda *args: args
+
# Rounding
ROUND_DOWN = 'ROUND_DOWN'
ROUND_HALF_UP = 'ROUND_HALF_UP'
@@ -820,7 +826,7 @@ class Decimal(object):
To show the internals exactly as they are.
"""
- return (self._sign, tuple(map(int, self._int)), self._exp)
+ return DecimalTuple(self._sign, tuple(map(int, self._int)), self._exp)
def __repr__(self):
"""Represents the number as an instance of Decimal."""