diff --git a/special-method-names.html b/special-method-names.html index e1d7264..6d77ecb 100644 --- a/special-method-names.html +++ b/special-method-names.html @@ -703,16 +703,18 @@ class FieldStorage: to serialize an object (new pickling protocol) pickle.dump(x, file, protocol_version) x.__reduce_ex__(protocol_version) - +* control over how an object is created during unpickling x = pickle.load(file) x.__getnewargs__() - +* to restore an object’s state after unpickling x = pickle.load(file) x.__setstate__() +

* To recreate a serialized object, Python needs to create a new object that looks like the serialized object, then set the values of all the attributes on the new object. The __getnewargs__() method controls how the object is created, then the __setstate__() method controls how the attribute values are restored. +

Classes That Can Be Used in a with Block

Python 3 supports the with statement, which allows you to access an object’s properties and methods without explicitly referencing the object every time. A with block defines a runtime context; you “enter” the context when you execute the with statement, and you “exit” the context after you execute the last statement in the block.