Skip to content

Commit

Permalink
Issue RafeKettler#44 as a commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Charley-Peng committed Mar 7, 2014
1 parent a0603f0 commit 5ad6108
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion magicmethods.tex
Original file line number Diff line number Diff line change
Expand Up @@ -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}

Expand Down

0 comments on commit 5ad6108

Please sign in to comment.