[Zope] How to check type of variable in DTML

Schmidt, Allen J. aschmidt@nv.cc.va.us
Fri, 10 May 2002 08:49:20 -0400


Thanks! That works great, sort of....

I changed the return to only 'list' or 'string' or 'integer' for easy
comparison.

In a dtml doc or method it works fine. In a ZSQL it does not. Seems =
that it
always sees the input parameters as strings...never a list - even when
entered as a list. ['Ford','Dodge',''] is seen as a string when checked
inside a dtml-if in the ZSQL method.

Are Pythonscripts handled somehow differently inside a ZSQL method? Or
something else??

Thanks all

-Allen

-----Original Message-----
From: Elena Schulz [mailto:elena.schulz@gmx.net]
Sent: Friday, May 10, 2002 6:56 AM
To: zope@zope.org
Subject: Re: [Zope] How to check type of variable in DTML


Hi Allen,

if you want to check the type of a variable use an external python =
script
like:

import string

def getType(x):
    if type(x) =3D=3D type([]):
        return "type(%s)=3Dlist" % (x)
    if type(x) =3D=3D type(""):
        return "type(%s)=3Dstring" % (x)
    if type(x) =3D=3D type(1):
        return "type(%s)=3Dinteger" % (x)
    if type(x) =3D=3D type({1:'s'}):
        return "type(%s)=3Ddictionary" % (x)
    if type(x) =3D=3D type((1)):
        return "type(%s)=3Dtuple" % (x)
    if type(x) =3D=3D type(string):
        return "type(%s)=3Dmodule" % (x)
    else:
        return "type(%s)=3Dobject o. =E4." % (x)

I took this idea from some earlier postings to the list.

Greetings,

Elena




_______________________________________________
Zope maillist  -  Zope@zope.org
http://lists.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists -=20
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope-dev )