Why are functions atomic?

Chris Mellon arkanes at gmail.com
Fri May 4 16:12:53 EDT 2007


On 4 May 2007 12:59:39 -0700, Michael <michael.forbes at gmail.com> wrote:
> On May 4, 9:19 am, John Nagle <n... at animats.com> wrote:
> > > ...     def g():
> > > ...         x = x + 1
> >
> >      Too cute.  Don't nest functions in Python; the scoping model
> > isn't really designed for it.
>
> How can you make generators then if you don't nest?
>

There's all kinds of good reasons to nest functions, and the "scoping
model isn't really designed for it" somewhat overstates the case -
it's not relevant to many of the reasons you might nest functions, and
it's not (much) of a problem for the rest of them. What you can't do
is rebind values in the enclosing scope, unless the enclosing scope is
global. That's a real, but fairly minor, limitation and you'll be able
to explicitly address your enclosing scope in 3k (or perhaps sooner).



More information about the Python-list mailing list