Newbie help - test for data type
John Machin
sjmachin at lexicon.net
Mon Jul 31 05:13:45 EDT 2006
Jonathan Bowlas wrote:
> Hi Listers,
>
> I have a requirement to test for a data type could someone tell me if this
> is possible in python?
>
> Basically I have a ZPT in Zope that users can select checkboxes in a form
> which pass arguments for a python function, however if there is only one
> checkbox selected it is passed as a string whereas more than one checkbox is
> passed as a list.
>
Fantastic. If there are 0 checkboxes selected, does it return None?
The built-in function isinstance() will help.
if it is None:
shouldbe = []
elif isinstance(it, str):
shouldbe = [it]
elif isinstance(it, list):
shouldbe = it
else:
raise WTFError(repr(type(it))
Cheers,
John
More information about the Python-list
mailing list