summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2012-03-17 15:58:12 (GMT)
committerGeorg Brandl <georg@python.org>2012-03-17 15:58:12 (GMT)
commit2ba1428911370cb8c98572ac4ceb3b4ea2e04ad3 (patch)
treeee77a488d39bb9f5511e38da9133de75cc3117f4
parent7add4eaa6d4a7ffd2f15821e962c8e6486deeef7 (diff)
parent12c3cd7c1f090cb055d395a5d54deba955af9d7b (diff)
downloadcpython-2ba1428911370cb8c98572ac4ceb3b4ea2e04ad3.zip
cpython-2ba1428911370cb8c98572ac4ceb3b4ea2e04ad3.tar.gz
cpython-2ba1428911370cb8c98572ac4ceb3b4ea2e04ad3.tar.bz2
merge with 3.2
-rw-r--r--Doc/faq/design.rst10
1 files changed, 5 insertions, 5 deletions
diff --git a/Doc/faq/design.rst b/Doc/faq/design.rst
index 5441fd4..43ec692 100644
--- a/Doc/faq/design.rst
+++ b/Doc/faq/design.rst
@@ -284,8 +284,9 @@ Similar methods exist for bytes and bytearray objects.
How fast are exceptions?
------------------------
-A try/except block is extremely efficient. Actually catching an exception is
-expensive. In versions of Python prior to 2.0 it was common to use this idiom::
+A try/except block is extremely efficient if no exceptions are raised. Actually
+catching an exception is expensive. In versions of Python prior to 2.0 it was
+common to use this idiom::
try:
value = mydict[key]
@@ -296,11 +297,10 @@ expensive. In versions of Python prior to 2.0 it was common to use this idiom::
This only made sense when you expected the dict to have the key almost all the
time. If that wasn't the case, you coded it like this::
- if mydict.has_key(key):
+ if key in mydict:
value = mydict[key]
else:
- mydict[key] = getvalue(key)
- value = mydict[key]
+ value = mydict[key] = getvalue(key)
For this specific case, you could also use ``value = dict.setdefault(key,
getvalue(key))``, but only if the ``getvalue()`` call is cheap enough because it