How to detect what type a variable is?

Daniel Klein danielkleinad at gmail.com
Wed Nov 29 11:37:23 EST 2006


On 29 Nov 2006 08:25:35 -0800, "Leandro Ardissone"
<lardissone at gmail.com> wrote:

>great, thanks
>
>And how I can compare this "<type 'str'>" output ?
>I want to decide what to do if the var is an string and what to do if
>not..
>
>Tried with:
>if type(artistList) == "<type 'list'>":
>
>and
>if type(artistList) == "list":
>
>but nothing..

Try it this way...

>>> artistList = []
>>> isinstance(artistList, list)
True
>>> if isinstance(artistList, list):
	print "I'm a list."

I'm a list.
>>> 


Daniel Klein



More information about the Python-list mailing list