[Tutor] validating decimal class

Kent Johnson kent37 at tds.net
Thu Nov 6 02:10:34 CET 2008


On Wed, Nov 5, 2008 at 7:09 PM, qsqgeekyogdty at tiscali.co.uk
<qsqgeekyogdty at tiscali.co.uk> wrote:
> I have an object which is:
>
>>>> type(price)
> <class 'decimal.Decimal'>
>
> but i can't figure how to validate against it.
>
>>>>if not isinstance(price, decimal.Decimal):
>          do something...

This should work, what problem are you having?

> how do i ensure that the object 'price' is a decimal?

Why do you need to know? Another approach is to just treat it as a
Decimal and catch the exception that is raised if it is not.

Kent


More information about the Tutor mailing list