[Zope] How to check type of variable in DTML

Elena Schulz elena.schulz@gmx.net
Fri, 10 May 2002 12:55:34 +0200


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