[Tutor] checking variable types

Lloyd Kvam pythonTutor at venix.com
Fri Apr 2 08:51:00 EST 2004


If you are using the cgi module and its FieldStorage class, the getlist
method will ALWAYS return a list, even for a single selection.

I do not remember which version of Python added that method, but if you
are using the current version of Python, I think that is the best way to
manage.

getfirst is the method to use if you NEVER want a list.  It discards the
extra choices.


On Mon, 2004-03-22 at 10:03, Marie Robichon wrote:
> Hi,
> 
> I have a mutliple select box in html which (unfortunately) returns a list 
> if someone makes a multiple selection but returns a string if someone 
> selects one item only.
> 
> How in my python script do I test whether it is a list or a string before I 
> do my processing ?
> 
> Thanks in advance from a newbie,
> 
> Marie
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
-- 

Lloyd Kvam
Venix Corp.
1 Court Street, Suite 378
Lebanon, NH 03766-1358

voice:	603-653-8139
fax:	801-459-9582




More information about the Tutor mailing list