[Python-Dev] annoying dictionary problem, non-existing keys
Oleg Broytmann
phd at phd.pp.ru
Thu Apr 24 04:17:35 EDT 2008
On Thu, Apr 24, 2008 at 11:13:25AM +0300, bvidinli wrote:
> if conf.has_key('key1'):
> if conf['key1']<>'':
> other commands....
>
> this is very annoying.
> in php, i was able to code only like:
> if conf['key1']=='someth'
>
> in python, this fails, because, if key1 does not exists, it raises an exception.
if conf.get('key1')=='someth':...
PS. Please do not cross-post so extensively.
Oleg.
--
Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru
Programmers don't die, they just GOSUB without RETURN.
More information about the Python-list
mailing list