468,471 Members | 1,686 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,471 developers. It's quick & easy.

Re: [Python-Dev] annoying dictionary problem, non-existing keys

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/ ph*@phd.pp.ru
Programmers don't die, they just GOSUB without RETURN.
Jun 27 '08 #1
0 1281

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by Berthold Hoellmann | last post: by
1 post views Thread by Jerald | last post: by
2 posts views Thread by Kurt B. Kaiser | last post: by
reply views Thread by Li Daobing | last post: by
31 posts views Thread by surfunbear | last post: by
reply views Thread by Fuzzyman | last post: by
reply views Thread by Kurt B. Kaiser | last post: by
8 posts views Thread by karthikbalaguru | last post: by
7 posts views Thread by Michele Simionato | last post: by
1 post views Thread by kmladenovski | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.