Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7f781c9

Browse files
committed
Add Pickler.clear_memo() so the pickle and cPickle modules are more similar.
1 parent 56aa628 commit 7f781c9

3 files changed

Lines changed: 15 additions & 4 deletions

File tree

Doc/lib/libpickle.tex

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,15 +237,20 @@ \subsection{Usage}
237237
or recursive objects pickled by reference and not by value. This
238238
method is useful when re-using picklers.
239239

240-
\strong{Note:} \method{clear_memo()} is only available on the picklers
241-
created by \module{cPickle}. In the \module{pickle} module, picklers
242-
have an instance variable called \member{memo} which is a Python
243-
dictionary. So to clear the memo for a \module{pickle} module
240+
\begin{notice}
241+
Prior to Python 2.3, \method{clear_memo()} was only available on the
242+
picklers created by \refmodule{cPickle}. In the \module{pickle} module,
243+
picklers have an instance variable called \member{memo} which is a
244+
Python dictionary. So to clear the memo for a \module{pickle} module
244245
pickler, you could do the following:
245246

246247
\begin{verbatim}
247248
mypickler.memo.clear()
248249
\end{verbatim}
250+
251+
Code that does not need to support older versions of Python should
252+
simply use \method{clear_memo()}.
253+
\end{notice}
249254
\end{methoddesc}
250255

251256
It is possible to make multiple calls to the \method{dump()} method of

Lib/pickle.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ def __init__(self, file, bin = 0):
115115
self.memo = {}
116116
self.bin = bin
117117

118+
def clear_memo(self):
119+
self.memo.clear()
120+
118121
def dump(self, object):
119122
self.save(object)
120123
self.write(STOP)

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ Extension modules
9999

100100
Library
101101

102+
- The pickle.Pickler class grew a clear_memo() method to mimic that
103+
provided by cPickle.Pickler.
104+
102105
- difflib's SequenceMatcher class now does a dynamic analysis of
103106
which elements are so frequent as to constitute noise. For
104107
comparing files as sequences of lines, this generally works better

0 commit comments

Comments
 (0)