[Zope-dev] Asking for the type of a variable

David S. Harrison dsh@magma-da.com
Tue, 09 Nov 1999 13:55:11 -0800


It looks like I need to ask for the type of a python variable from DTML.
So far, I haven't been able to get this to work:

  <dtml-if "type(TAG)==type('x')">

I am trying to see if the TAG variable is a string.  Zope complains about
"type".  I tried using the special name space:

  <dtml-if "_.type(TAG)==_.type('x')">

But it looks like "type" is not a function available through that means.
Is there another way to use the type of a variable for branching?

Actually, the reason this arises is forms.  I have a series of radio
buttons in a form.  When submitted to Zope, I notice that if one item
is selected, the value is a string.  When many items are selected,
the value is a list of strings.  Since <dtml-in> does not accept a
single string as an argument, I need to test to see if the incoming
value is a string or a list of strings before processing it.  I will
gladly accept any better idioms for handling this case.  The tests
certainly make the DTML code more complex than I think it should be.

				David S. Harrison
				(dsh@magma-da.com)