Building and Transvering multi-level dictionaries

Eric Hagemann ehagemann at home.com
Mon Mar 20 21:38:14 EST 2000


Nathan,
	Thanks for the correction. I guess my many years of C programming shows through !

Cheers
Eric


-----Original Message-----
From:	Nathan Clegg [SMTP:nathan at islanddata.com]
Sent:	Monday, March 20, 2000 9:05 PM
To:	Eric Hagemann
Cc:	python-list at python.org
Subject:	Re: Building and Transvering multi-level dictionaries


On 21-Mar-2000 Eric Hagemann wrote:
>#add a key and setup for a sub-dictionary
> if(D.has_key('a') == 0)
>     D['a'] = {}


In my opinion, this is a very dangerous habit to get into.  Unlike C,
perl and python have more than one false value.  I don't know that
you can be sure that a built-in such as this is guaranteed to be
consistent between versions of python.  Even more dangerous is that
modules and functions written by others could use any of the false
values.  I personally always return None for false.  Seems to me much
safer to do:

if not D.has_key('a'):
        D['a'] = {}


----------------------------------
Nathan Clegg
 nathan at islanddata.com






More information about the Python-list mailing list