Skip to content

Commit bfe95ac

Browse files
committed
Recorded merge of revisions 76886 via svnmerge from
svn+ssh://[email protected]/python/trunk ........ r76886 | georg.brandl | 2009-12-19 18:43:33 +0100 (Sa, 19 Dez 2009) | 1 line #7493: review of Design FAQ by Florent Xicluna. ........
1 parent 4d345ce commit bfe95ac

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

Doc/faq/design.rst

+9-6
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,10 @@ code breakage.
234234

235235
.. XXX talk about protocols?
236236
237-
Note that for string operations Python has moved from external functions (the
238-
``string`` module) to methods. However, ``len()`` is still a function.
237+
.. note::
238+
239+
For string operations, Python has moved from external functions (the
240+
``string`` module) to methods. However, ``len()`` is still a function.
239241

240242

241243
Why is join() a string method instead of a list or tuple method?
@@ -306,14 +308,15 @@ expensive. In versions of Python prior to 2.0 it was common to use this idiom::
306308
This only made sense when you expected the dict to have the key almost all the
307309
time. If that wasn't the case, you coded it like this::
308310

309-
if dict.has_key(key):
311+
if key in dict(key):
310312
value = dict[key]
311313
else:
312314
dict[key] = getvalue(key)
313315
value = dict[key]
314316

315-
(In Python 2.0 and higher, you can code this as ``value = dict.setdefault(key,
316-
getvalue(key))``.)
317+
For this specific case, you could also use ``value = dict.setdefault(key,
318+
getvalue(key))``, but only if the ``getvalue()`` call is cheap enough because it
319+
is evaluated in all cases.
317320

318321

319322
Why isn't there a switch or case statement in Python?
@@ -750,7 +753,7 @@ requested again. This is called "memoizing", and can be implemented like this::
750753

751754
# Callers will never provide a third parameter for this function.
752755
def expensive (arg1, arg2, _cache={}):
753-
if _cache.has_key((arg1, arg2)):
756+
if (arg1, arg2) in _cache:
754757
return _cache[(arg1, arg2)]
755758

756759
# Calculate the value

0 commit comments

Comments
 (0)