]> granicus.if.org Git - python/commitdiff
Have Decimal.as_tuple return a named tuple.
authorRaymond Hettinger <python@rcn.com>
Fri, 11 Jan 2008 02:24:13 +0000 (02:24 +0000)
committerRaymond Hettinger <python@rcn.com>
Fri, 11 Jan 2008 02:24:13 +0000 (02:24 +0000)
Lib/decimal.py

index 3ee078f570daf1303521f28fe776a42a380df86a..8b548216143486ba7f21543adba4e6492c3759e0 100644 (file)
@@ -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."""