How to tell the difference between string and list

Gerhard Häring gh at ghaering.de
Fri Dec 5 10:01:37 EST 2003


Skip Montanaro wrote:
>     Jan> I need to recognize 'var' and ['var'], usually I would use:
> 
>     ...
> 
> Try
> 
>     if isinstance(a, str):
>         pass
>     elif isinstance(a, list):
>         pass

This requires Python 2.2 or later, but ZOPE still uses Python 2.1 AFAIK, so you 
can try one of the Python 2.1 compatible solutions that I proposed.

-- Gerhard






More information about the Python-list mailing list