How to tell the difference between string and list

Michael Hudson mwh at
Fri Dec 5 16:14:51 CET 2003

Jan Kokoska <kokoska.jan at> writes:

> Hello,
> I need to recognize 'var' and ['var'], usually I would use:
> if a.__class__() == '':
> 	#string
> elif a.__class__() == []:
> 	#list

That's a very strange way of doing it in any situation!


  This is an off-the-top-of-the-head-and-not-quite-sober suggestion,
  so is probably technically laughable.  I'll see how embarassed I
  feel tomorrow morning.            -- Patrick Gosling, ucam.comp.misc

More information about the Python-list mailing list