[ python-Bugs-891367 ] dict.get() evaluates second parameter even if key is present

SourceForge.net noreply at sourceforge.net
Thu Feb 5 18:07:22 EST 2004


Bugs item #891367, was opened at 2004-02-05 17:06
Message generated for change (Comment added) made by rhettinger
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=891367&group_id=5470

Category: Build
Group: None
>Status: Closed
>Resolution: Invalid
Priority: 5
Submitted By: Claude Belisle (claude_belisle)
Assigned to: Nobody/Anonymous (nobody)
Summary: dict.get() evaluates second parameter even if key is present

Initial Comment:
The optional parameter passed to get gets evaluated
even when the key is indeed present in the dictionary.
See attached file for the code I was using when
stumbling across this behaviour.

----------------------------------------------------------------------

>Comment By: Raymond Hettinger (rhettinger)
Date: 2004-02-05 18:07

Message:
Logged In: YES 
user_id=80475

Unfortunately, that it is what it is supposed to do.

Workaround:

try:
    v = mydict[k]
except AttributeError:
    v = defaultmaker()



----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=891367&group_id=5470



More information about the Python-bugs-list mailing list