Checking if a variable is a dictionary

Bruno Desthuilliers bruno.42.desthuilliers at wtf.websiteburo.oops.com
Thu Mar 6 07:40:17 EST 2008


Guillermo a écrit :
> Hello,
> 
> This is my first post here. I'm getting my feet wet with Python and I
> need to know how can I check whether a variable is of type dictionary.

What makes you say you "need" to know this ? Except for a couple corner 
cases, you usually don't need to care about this. If you told us more 
about the actual problem (instead of asking about what you think is the 
solution), we might be of more help...

> Something like this:
> 
> if isdict(a) then print "a is a dictionary"

Should this work for subclasses of dicts ? Should this work for 
non-subclasses of dict implementing the dict protocol ?



More information about the Python-list mailing list