[Tutor] validating decimal class
bcl at brianlane.com
Thu Nov 6 02:12:49 CET 2008
-----BEGIN PGP SIGNED MESSAGE-----
qsqgeekyogdty at tiscali.co.uk wrote:
> silly question, but i can't seem to figure it it.
> I have an object which is:
> <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()?
- ---[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!
-----END PGP SIGNATURE-----
More information about the Tutor