mirror of https://github.com/python/cpython.git
Add Pickler.clear_memo() so the pickle and cPickle modules are more similar.
This commit is contained in:
parent
56aa6280f6
commit
7f781c9aab
|
@ -237,15 +237,20 @@ remembers which objects the pickler has already seen, so that shared
|
||||||
or recursive objects pickled by reference and not by value. This
|
or recursive objects pickled by reference and not by value. This
|
||||||
method is useful when re-using picklers.
|
method is useful when re-using picklers.
|
||||||
|
|
||||||
\strong{Note:} \method{clear_memo()} is only available on the picklers
|
\begin{notice}
|
||||||
created by \module{cPickle}. In the \module{pickle} module, picklers
|
Prior to Python 2.3, \method{clear_memo()} was only available on the
|
||||||
have an instance variable called \member{memo} which is a Python
|
picklers created by \refmodule{cPickle}. In the \module{pickle} module,
|
||||||
dictionary. So to clear the memo for a \module{pickle} module
|
picklers have an instance variable called \member{memo} which is a
|
||||||
|
Python dictionary. So to clear the memo for a \module{pickle} module
|
||||||
pickler, you could do the following:
|
pickler, you could do the following:
|
||||||
|
|
||||||
\begin{verbatim}
|
\begin{verbatim}
|
||||||
mypickler.memo.clear()
|
mypickler.memo.clear()
|
||||||
\end{verbatim}
|
\end{verbatim}
|
||||||
|
|
||||||
|
Code that does not need to support older versions of Python should
|
||||||
|
simply use \method{clear_memo()}.
|
||||||
|
\end{notice}
|
||||||
\end{methoddesc}
|
\end{methoddesc}
|
||||||
|
|
||||||
It is possible to make multiple calls to the \method{dump()} method of
|
It is possible to make multiple calls to the \method{dump()} method of
|
||||||
|
|
|
@ -115,6 +115,9 @@ def __init__(self, file, bin = 0):
|
||||||
self.memo = {}
|
self.memo = {}
|
||||||
self.bin = bin
|
self.bin = bin
|
||||||
|
|
||||||
|
def clear_memo(self):
|
||||||
|
self.memo.clear()
|
||||||
|
|
||||||
def dump(self, object):
|
def dump(self, object):
|
||||||
self.save(object)
|
self.save(object)
|
||||||
self.write(STOP)
|
self.write(STOP)
|
||||||
|
|
|
@ -99,6 +99,9 @@ Extension modules
|
||||||
|
|
||||||
Library
|
Library
|
||||||
|
|
||||||
|
- The pickle.Pickler class grew a clear_memo() method to mimic that
|
||||||
|
provided by cPickle.Pickler.
|
||||||
|
|
||||||
- difflib's SequenceMatcher class now does a dynamic analysis of
|
- difflib's SequenceMatcher class now does a dynamic analysis of
|
||||||
which elements are so frequent as to constitute noise. For
|
which elements are so frequent as to constitute noise. For
|
||||||
comparing files as sequences of lines, this generally works better
|
comparing files as sequences of lines, this generally works better
|
||||||
|
|
Loading…
Reference in New Issue