On this page
pickle.dump
Up: pickle | Next: pickle.dumps
Rel: pickle.dumps, pickle.load, pickle.loads, pickle.PickleBuffer
Ref: docs.python.org — pickle.dump
Tags: #public #python3 #stdlib #pickle
Import
import pickle
from pickle import dump
Signature & Overview
pickle.dump(obj, file, protocol=None, *, fix_imports=True, buffer_callback=None)
Write a pickled representation of obj to the open file object file.
Usage
import io
import pickle
buf = io.BytesIO()
pickle.dump({"a": 1}, buf, protocol=pickle.HIGHEST_PROTOCOL)
buf.seek(0)
assert pickle.load(buf) == {"a": 1}
Gotchas
- Requires binary mode (
"wb"): Passprotocol=pickle.HIGHEST_PROTOCOLfor smaller, faster payloads.
REPL Inspect
from pickle import dump
help(dump)
Linked from
- tuts/python3/stdlib_module/pickle
- tuts/python3/stdlib_module/pickle/dumps
- tuts/python3/stdlib_module/pickle/load
- tuts/python3/stdlib_module/pickle/loads
- tuts/python3/stdlib_module/pickle/PickleBuffer
- tuts/python3/stdlib_module/pickle/PickleError
- tuts/python3/stdlib_module/pickle/Pickler
- tuts/python3/stdlib_module/pickle/PicklingError
- tuts/python3/stdlib_module/pickle/Unpickler
- tuts/python3/stdlib_module/pickle/UnpicklingError
Related notes
- tuts/python3/stdlib_module/pickle/dumps Linked here; links to this page; shared tags: #pickle, #stdlib
- tuts/python3/stdlib_module/pickle/load Linked here; links to this page; shared tags: #pickle, #stdlib
- tuts/python3/stdlib_module/pickle/loads Linked here; links to this page; shared tags: #pickle, #stdlib
- tuts/python3/stdlib_module/pickle/PickleBuffer 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/PickleError links to this page; shared tags: #pickle, #stdlib
- tuts/python3/stdlib_module/pickle/Pickler links to this page; shared tags: #pickle, #stdlib
- tuts/python3/stdlib_module/pickle/PicklingError links to this page; shared tags: #pickle, #stdlib
- tuts/python3/stdlib_module/pickle/Unpickler links to this page; shared tags: #pickle, #stdlib
- tuts/python3/stdlib_module/pickle/UnpicklingError links to this page; shared tags: #pickle, #stdlib