On this page
pickle.Pickler
Prev: pickle.PickleError | Up: pickle | Next: pickle.PicklingError
Rel: pickle.dump, pickle.dumps, pickle.load, pickle.loads
Ref: docs.python.org — pickle.Pickler
Tags: #public #python3 #stdlib #pickle
Import
import pickle
from pickle import Pickler
Signature & Overview
pickle.Pickler(file, protocol=None, fix_imports=True, buffer_callback=None)
This takes a binary file for writing a pickle data stream.
Methods & Attributes
Pickler.clear_memo(self, /)— Clears the pickler's "memo".Pickler.dump(self, obj, /)— Write a pickled representation of the given object to the open file.Pickler.persistent_id(self, obj, /)—Pickler.persistent_idmethod/property.
Usage
import io
import pickle
buf = io.BytesIO()
pickle.Pickler(buf, protocol=pickle.HIGHEST_PROTOCOL).dump({"k": [1, 2]})
buf.seek(0)
assert pickle.load(buf) == {"k": [1, 2]}
Gotchas
- Subclass
Picklerto overridepersistent_id()ordispatch_tablefor custom serialization.
REPL Inspect
from pickle import Pickler
help(Pickler)
Linked from
Related notes
- tuts/python3/stdlib_module/pickle/PickleError Linked here; links to this page; shared tags: #pickle, #stdlib
- tuts/python3/stdlib_module/pickle/PicklingError Linked here; links to this page; shared tags: #pickle, #stdlib
- tuts/python3/stdlib_module/pickle Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/pickle/dump Linked here; shared tags: #pickle, #stdlib
- tuts/python3/stdlib_module/pickle/dumps Linked here; shared tags: #pickle, #stdlib
- tuts/python3/stdlib_module/pickle/load Linked here; shared tags: #pickle, #stdlib
- tuts/python3/stdlib_module/pickle/loads Linked here; shared tags: #pickle, #stdlib
- tuts/python3/stdlib_module/pickle/PickleBuffer shared tags: #pickle, #stdlib
- tuts/python3/stdlib_module/pickle/Unpickler shared tags: #pickle, #stdlib
- tuts/python3/stdlib_module/pickle/UnpicklingError shared tags: #pickle, #stdlib