[Python-Dev] decimal API

Batista, Facundo FBatista at uniFON.com.ar
Mon Jul 5 19:41:37 CEST 2004


[Raymond Hettinger]

#- So, my question for the group is whether to:
#- 
#- * leave it as-is
#- * raise a ValueError just like float('abc') or int('abc')
#- * raise an Invalid Operation and return a quiet NaN.

I'll go for leaving it as-is:

>>> import Decimal
>>> d = Decimal.Decimal('rdd')
>>> d
Decimal("NaN")
>>> Decimal.getcontext().trap_enablers[Decimal.ConversionSyntax] = True
>>> d = Decimal.Decimal('rdd')
Traceback (most recent call last):
  File "<pyshell#6>", line 1, in ?
    d = Decimal.Decimal('rdd')
  File "D:\Facundo\python\Decimal.py", line 445, in __init__
    >>> Decimal(314)                 # int or long
  File "D:\Facundo\python\Decimal.py", line 594, in _convertString
    return self._int != (0,)*len(self._int)
  File "D:\Facundo\python\Decimal.py", line 2167, in _raise_error
ConversionSyntax

If you want an exception, you got it easily.

.	Facundo

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.713 / Virus Database: 469 - Release Date: 30/06/2004
 



More information about the Python-Dev mailing list