diff options
Diffstat (limited to 'Doc/ref/ref7.tex')
-rw-r--r-- | Doc/ref/ref7.tex | 20 |
1 files changed, 3 insertions, 17 deletions
diff --git a/Doc/ref/ref7.tex b/Doc/ref/ref7.tex index b8fac0b..9107fe9 100644 --- a/Doc/ref/ref7.tex +++ b/Doc/ref/ref7.tex @@ -364,23 +364,9 @@ allows the execution of multiple statements. \strong{Programmer's note:} a ``\code{def}'' form executed inside a function definition defines a local function that can be returned or -passed around. Because of Python's two-scope philosophy, a local -function defined in this way does not have access to the local -variables of the function that contains its definition; the same rule -applies to functions defined by a lambda form. A standard trick to -pass selected local variables into a locally defined function is to -use default argument values, like this: - -\begin{verbatim} -# Return a function that returns its argument incremented by 'n' -def make_incrementer(n): - def increment(x, n=n): - return x+n - return increment - -add1 = make_incrementer(1) -print add1(3) # This prints '4' -\end{verbatim} +passed around. The semantics of name resolution in the nested +function will change in Python 2.2. See the appendix for a +description of the new semantics. \section{Class definitions\label{class}} \indexii{class}{definition} |