Nested scopes: design or implementation?

Terry Reedy tejarex at yahoo.com
Tue Mar 5 22:32:54 EST 2002


"logistix" <logstx at bellatlantic.net> wrote in message
news:vcfh8.405$tL.70 at nwrddc02.gnilink.net...
> Is the following code operating this way by design or is it just
> implementation?  It seems to indicate that the nested function is
redefined
> each time the parent function is called.  Is this necessary or
desirable?

It is consistent with the Python execution model.  'def' is an
*executable* statement, not a declaration.  When 'def' occurs and is
encountered at module level, it is executed.  When a function is
called, *all* the statements within (except 'global' declarations) are
executed as encountered.

Terry J. Reedy






More information about the Python-list mailing list