我该如何理解酸洗和解酸洗工作原理的描述?
How shall I understand this description of how pickling and unpickling work?
Python in a Nutshell 中对 pickling 和 unpickling 的以下描述让我感到困惑。我不清楚 "otherwise" 和 "in this one case" 的用法,我不确定它们指的是什么情况。如果您能以更清晰的方式(也许是伪代码)重新表述,我将不胜感激?
Here is how pickle saves the state of instance object x of class
T and later reloads the saved state into a new instance y of T
(the first step of the reloading is always to make a new empty
instance y of T , except where we explicitly say otherwise in the
following):
• When T
supplies the method __getstate__
, pickle saves the
result d of calling T.__getstate__(x)
.
• When T
supplies the method __setstate__
, d
can be of any
type, and pickle reloads the saved state by calling
T.__setstate__(y, d)
.
• Otherwise, d
must be a dictionary, and pickle just sets
y.__dict__ = d
.
• Otherwise, when T
supplies the method __getnewargs__
, and
pickle is pickling with protocol 2 or higher, pickle saves the
result t
of calling T.__getnewargs__(x)
; t
must be a
tuple.
• pickle , in this one case, does not start with an empty y
, but
rather creates y
by executing y = T.__new__(T, *t)
, which
concludes the reloading.
• Otherwise, by default, pickle saves as d
the dictionary
x.__dict__
.
• When T
supplies the method __setstate__
, pickle reloads
the saved state by calling T.__setstate__ (y, d)
.
• Otherwise, pickle just sets y.__dict__ = d
.
该描述确实需要缩进或其他内容以更好地表明什么是什么。这是它试图说的,作为流程图:
Python in a Nutshell 中对 pickling 和 unpickling 的以下描述让我感到困惑。我不清楚 "otherwise" 和 "in this one case" 的用法,我不确定它们指的是什么情况。如果您能以更清晰的方式(也许是伪代码)重新表述,我将不胜感激?
Here is how pickle saves the state of instance object x of class T and later reloads the saved state into a new instance y of T (the first step of the reloading is always to make a new empty instance y of T , except where we explicitly say otherwise in the following):
• When
T
supplies the method__getstate__
, pickle saves the result d of callingT.__getstate__(x)
.• When
T
supplies the method__setstate__
,d
can be of any type, and pickle reloads the saved state by callingT.__setstate__(y, d)
.• Otherwise,
d
must be a dictionary, and pickle just setsy.__dict__ = d
.• Otherwise, when
T
supplies the method__getnewargs__
, and pickle is pickling with protocol 2 or higher, pickle saves the resultt
of callingT.__getnewargs__(x)
;t
must be a tuple.• pickle , in this one case, does not start with an empty
y
, but rather createsy
by executingy = T.__new__(T, *t)
, which concludes the reloading.• Otherwise, by default, pickle saves as
d
the dictionaryx.__dict__
.• When
T
supplies the method__setstate__
, pickle reloads the saved state by callingT.__setstate__ (y, d)
.• Otherwise, pickle just sets
y.__dict__ = d
.
该描述确实需要缩进或其他内容以更好地表明什么是什么。这是它试图说的,作为流程图: