mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
concrete example of why retaining old objects is good
This commit is contained in:
parent
347c30d217
commit
20a8336ff7
1 changed files with 9 additions and 1 deletions
|
@ -830,7 +830,15 @@ class C(object):
|
||||||
old version, the old definition remains. This feature can be used
|
old version, the old definition remains. This feature can be used
|
||||||
to the module's advantage if it maintains a global table or cache of
|
to the module's advantage if it maintains a global table or cache of
|
||||||
objects --- with a \keyword{try} statement it can test for the
|
objects --- with a \keyword{try} statement it can test for the
|
||||||
table's presence and skip its initialization if desired.
|
table's presence and skip its initialization if desired:
|
||||||
|
|
||||||
|
\begin{verbatim}
|
||||||
|
try:
|
||||||
|
cache
|
||||||
|
except NameError:
|
||||||
|
cache = {}
|
||||||
|
\end{verbatim}
|
||||||
|
|
||||||
|
|
||||||
It is legal though generally not very useful to reload built-in or
|
It is legal though generally not very useful to reload built-in or
|
||||||
dynamically loaded modules, except for \refmodule{sys},
|
dynamically loaded modules, except for \refmodule{sys},
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue