[Python-checkins] r59905 - python/trunk/Lib/decimal.py

raymond.hettinger python-checkins at python.org
Fri Jan 11 03:24:13 CET 2008


Author: raymond.hettinger
Date: Fri Jan 11 03:24:13 2008
New Revision: 59905
Modified:
 python/trunk/Lib/decimal.py
Log:
Have Decimal.as_tuple return a named tuple.
Modified: python/trunk/Lib/decimal.py
==============================================================================
--- python/trunk/Lib/decimal.py	(original)
+++ python/trunk/Lib/decimal.py	Fri Jan 11 03:24:13 2008
@@ -136,6 +136,12 @@
 
 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 @@
 
 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."""


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /