[Tutor] validating decimal class
Brian Lane
bcl at brianlane.com
Thu Nov 6 02:12:49 CET 2008
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
qsqgeekyogdty at tiscali.co.uk wrote:
> hello
> silly question, but i can't seem to figure it it.
>
> 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...
>
> how do i ensure that the object 'price' is a decimal?
>
The above should work (I even tried it to make sure).
But you could also compare it to a known type:
if not type(price) is type(decimal.Decimal(0)):
print "Not Decimal"
What error are you getting when you try using isinstance()?
Brian
- --
- ---[Office 70.0F]--[Outside 47.4F]--[Server 103.2F]--[Coaster 67.3F]---
- ---[ TACOMA WSF (366772760) @ 47 36.0979 -122 27.0253 ]---
Software, Linux, Microcontrollers http://www.brianlane.com
AIS Parser SDK http://www.aisparser.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (Darwin)
Comment: Remember Lexington Green!
iD8DBQFJEkSRIftj/pcSws0RAmQkAJ9Y+eFJym2qwqgGl2pDbxAH0gr2xwCggETX
LJISNKXlvKhCCveTzUAUzMY=
=clEC
-----END PGP SIGNATURE-----
More information about the Tutor
mailing list