Checking if a variable is a dictionary

Bruno Desthuilliers bruno.42.desthuilliers at wtf.websiteburo.oops.com
Thu Mar 6 15:52:41 CET 2008


Jeffrey Seifried a écrit :
(snip)
> if type(a)==type({}):
>     print 'a is a dictionary'

This instanciates a dict, call type() on it, and discard the dict - 
which is useless since the dict type is a builtin. Also, when you want 
to test identity, use an identity test.

if type(a) is dict:
    print "blah blah blah"



More information about the Python-list mailing list