Hi, I wonder if someone knows how to test a variables data type. e.g. if <dtml-var a> is integer or string. Thanks, Flavio Maciel IT Development & Support Welke Customs Brokers Welke Global Logistics Tel : (416)674-7606 x.268 Fax: (416) 674-1635 mailto:flavio@welke.com --- Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.461 / Virus Database: 260 - Release Date: 3/10/2003
F> I wonder if someone knows how to test a variables data type. e.g. if F> <dtml-var a> is integer or string. IIRC python scripts have a special function : same_type(var1, var2) if same_type(a, 'any string'): return "string !!" python's normal way , type(a) is restricted for security reasons i believe, but you can always do it in an external method if you really need it.. -- Geir Bækholt
On Thu, Mar 13, 2003 at 04:29:25PM -0500, Flavio wrote:
Hi,
I wonder if someone knows how to test a variables data type. e.g. if <dtml-var a> is integer or string.
What are you really trying to do? Doing different things based on type is not good: it leads to code that can't treat objects polymorphically. Somebody creates a string-like class and then discovers it won't work with your code because you can't handle anything that isn't really "a string". In general, python makes it "easier to ask forgiveness than permission" ... so you might do things like: # i want to use x as an integer try: x = int(x) except TypeError: return "x can't be used as an integer!" # i want to use y as a string try: y + '' except TypeError: return "y is not string-like!" -- Paul Winkler http://www.slinkp.com Look! Up in the sky! It's THE SOLID GOAT! (random hero from isometric.spaceninja.com)
participants (3)
-
Flavio -
Geir Bækholt -
Paul Winkler