How to tell the difference between string and list

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


Jan Kokoska <kokoska.jan at globe.cz> 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!

Cheers,
mwh

-- 
  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