determining type
shindich at my-deja.com
shindich at my-deja.com
Thu Jul 13 15:45:20 EDT 2000
In article <396e07fd at news-out>,
"Mike Mikkelsen" <mikk at microbsys.com> wrote:
> Hello All,
>
> Is there a way, programmatically, to determine if an item in a
dictionairy is itself a dictionairy?
>
> consider:
> >>> a = {'item1': 'hello', 'item2':{'subitem1':'goodbye'}}
> >>> print a['item2']['subitem1']
> goodbye
>
> Is there a way to tell if 'item2' is a dictionairy, list or simple
value like 'item1'?
>
> TIA
>
> --
> Mike Mikkelsen mikk at microbsys.com
> Micro Business Systems http://microbsys.com
> Fresno Linux Users Group http://linux.fresno.ca.us
>
> It's all GNU to me!
>
>
Try this:
if type (a['item2']) == type ({}):
print 'It\'s a dictionary'
else:
print type (a['item2'])
I hope this helps!
Alex Shindich
http://www.shindich.com/
Sent via Deja.com http://www.deja.com/
Before you buy.
More information about the Python-list
mailing list