From 5ad6108a68814be2c8df29d159a458aba88d44da Mon Sep 17 00:00:00 2001 From: Charley Peng Date: Fri, 7 Mar 2014 12:16:09 +1100 Subject: [PATCH] Issue #44 as a commit --- magicmethods.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/magicmethods.tex b/magicmethods.tex index 6cbc765..3dfe35b 100755 --- a/magicmethods.tex +++ b/magicmethods.tex @@ -41,7 +41,7 @@ \section{Construction and Initialization} \item[\code{__init__(self, [...)}] The initializer for the class. It gets passed whatever the primary constructor was called with (so, for example, if we called \code{x = SomeClass(10, 'foo')}, \code{__init__} would get passed \code{10} and \code{'foo'} as arguments. \code{__init__} is almost universally used in Python class definitions. \item[\code{__del__(self)}] -If \code{__new__} and \code{__init__} formed the constructor of the object, \code{__del__} is the destructor. It doesn't implement behavior for the statement \code{del x} (so that code would not translate to \code{x.__del__()}). Rather, it defines behavior for when an object is garbage collected. It can be quite useful for objects that might require extra cleanup upon deletion, like sockets or file objects. Be careful, however, as there is no guarantee that \code{__del__} will be executed if the object is still alive when the interpreter exits, so \code{__del__} can't serve as a replacement for good coding practices (like always closing a connection when you're done with it. In fact, \code{__del__} should almost never be used because of the precarious circumstances under which it is called; use it with caution! +If \code{__new__} and \code{__init__} formed the constructor of the object, \code{__del__} is the destructor. It doesn't implement behavior for the statement \code{del x} (so that code would not translate to \code{x.__del__()}). Rather, it defines behavior for when an object is garbage collected. It can be quite useful for objects that might require extra cleanup upon deletion, like sockets or file objects. Be careful, however, as there is no guarantee that \code{__del__} will be executed if the object is still alive when the interpreter exits, so \code{__del__} can't serve as a replacement for good coding practices (like always closing a connection when you're done with it). In fact, \code{__del__} should almost never be used because of the precarious circumstances under which it is called; use it with caution! \end{description}