Checking if a variable is a dictionary
Gabriel Genellina
gagsl-py2 at yahoo.com.ar
Thu Mar 6 07:35:38 EST 2008
En Thu, 06 Mar 2008 10:10:47 -0200, Guillermo
<guillermo.listas at googlemail.com> escribi�:
> 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.
>
> Something like this:
>
> if isdict(a) then print "a is a dictionary"
if isinstance(a, dict): ...
But note that it's more common in Python to try to use it in the intended
way, and catch the possible errors.
Look for "duck typing" in this group, and the difference between "easier
to ask forgiveness
than permission" and "look before you leap".
--
Gabriel Genellina
More information about the Python-list
mailing list