Name
pickle
Synopsis
pickle(type,fred,fcon=None)
Registers function fred as the reduction
function for type type, where
type must be a type object (not a class).
To save any object o of type
type, module pickle
calls
fred
(
o
)
and saves fred’s result.
fred
(
o
)
must return a pair
(
fcon,t
)
or a tuple
(
fcon,t,d
),
where fcon is a safe constructor and
t is a tuple. To reload
o, pickle calls
o
=
fcon
(*
t
).
Then, if fred returned a
d, pickle uses
d to restore
o’s state, as in
“Pickling of instance objects”
(o
.__setstate__(
d
) if
o supplies __setstate__, otherwise o
.__dict__.update(
d
)).
If fcon is not None,
pickle also calls
constructor(
fcon
)
to register fcon as a safe
constructor.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access