New submission from Mark Dickinson <dicki...@gmail.com>: Ezio Melotti asked (on #python-dev) why the Decimal constructor doesn't accept decimal digits other than 0-9. As far as I can tell there's no good reason for it not to. Moreover, the standard on which the decimal module is based says[1]:
"""It is recommended that implementations also provide additional number formatting routines (including some which are locale-dependent), and if available should accept non-European decimal digits in strings.""" All other builtin or standard library numeric types already accept such digits: Python 3.2a0 (py3k:74247, Jul 29 2009, 09:28:12) [GCC 4.0.1 (Apple Inc. build 5493)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> from fractions import Fraction >>> from decimal import Decimal >>> x = '\uff11\uff10\uff15\uff18\uff15' >>> x '10585' >>> int(x) 10585 >>> float(x) 10585.0 >>> complex(x) (10585+0j) >>> Fraction(x) Fraction(10585, 1) >>> Decimal(x) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/Users/dickinsm/python/svn/py3k/Lib/decimal.py", line 548, in __new__ "Invalid literal for Decimal: %r" % value) File "/Users/dickinsm/python/svn/py3k/Lib/decimal.py", line 3816, in _raise_error raise error(explanation) decimal.InvalidOperation: Invalid literal for Decimal: '10585' I propose adding support for this in Python 3.2 and (possibly) 2.7. The change would be for input only: no record of the original form of the digits would be kept by the Decimal object itself, so that e.g., str(Decimal('10585')) would still be '10585'. [1] See http://speleotrove.com/decimal/daconvs.html ---------- assignee: marketdickinson components: Library (Lib) messages: 91030 nosy: ezio.melotti, marketdickinson severity: normal status: open title: Make Decimal constructor accept all unicode decimal digits in input. type: feature request versions: Python 3.2 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue6595> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com