[Tutor] validating decimal class

A.T.Hofkamp a.t.hofkamp at tue.nl
Thu Nov 6 09:00:31 CET 2008


John Fouhy wrote:
> 2008/11/6 Brian Lane <bcl at brianlane.com>:
>> But you could also compare it to a known type:
>>
>> if not type(price) is type(decimal.Decimal(0)):
>>  print "Not Decimal"
> 
> Easier to just compare with decimal.Decimal:
> 
>>>> import decimal
>>>> d = decimal.Decimal(13)
>>>> type(d) == decimal.Decimal
> True

And since classes are singletons, you can use 'is' instead of '=='.




More information about the Tutor mailing list