From: Raymond Hettinger Date: Fri, 11 Jan 2008 02:24:13 +0000 (+0000) Subject: Have Decimal.as_tuple return a named tuple. X-Git-Tag: v2.6a1~648 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=097a1903035f9ee2efb1953306123f183124125d;p=thirdparty%2FPython%2Fcpython.git Have Decimal.as_tuple return a named tuple. --- diff --git a/Lib/decimal.py b/Lib/decimal.py index 3ee078f570da..8b5482161434 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."""