Easy Q

Dave Angel davea at ieee.org
Sat Jan 9 19:02:22 CET 2010

Victor Subervi wrote:
> Hi;
> I have a string.join statement on a variable that comes from a
> cgi.FieldStorage().getlist. The variable may be a list or a single value. I
> need to treat it differently depending on which it is. How can I distinguish
> it? len(var) will obviously give me the length of the string if it's a
> string and the length of the list if it's a list.
> TIA,
> beno
If you have to do an explicit type check of your variable, use an if 
statement, and the isinstance() built-in function.  Note that you can 
check for multiple types, like list and tuple, in the same function call.


More information about the Python-list mailing list