Reasoning behind nested scope

Andy Baker andy at andybak.net
Tue Aug 3 10:42:11 EDT 2004


I don't particularly. I just wanted to get a feel for the syntax and if it
was possible.

Although I can see some utility for grouping functions in a namespace.
Modules do that quite nicely but sometimes I want everything in one .py
file.

I found nested functions interesting as they seemed to enforce encapsulation
more strongly than Python does in areas where you would traditionally expect
strong encapsulation (i.e. private properties in objects).

> -----Original Message-----
> From: Chris Cioffi [mailto:evenprimes at gmail.com] 
> Sent: 03 August 2004 15:24
> To: andy at andybak.net
> Cc: python-list at python.org; andybak at gmail.com
> Subject: Re: Reasoning behind nested scope
> 
> Why would you want to do this?  The whole point of a nested 
> function, I thought, was to encapsulate some code in the 
> surrounding function, usually to make the surrounding 
> function clearer.  If the nested function is of wider utility 
> it should just be a module level function.  (Possibly of the 
> quasi private variety Python offers.)
> 
> Chris
> 
> On Tue, 3 Aug 2004 12:26:15 +0100, Andy Baker 
> <andy at andybak.net> wrote:
> [snip]
> > (On a side note is there any way to call a nested function from 
> > outside the parent? I was kind of expecting nested functions to be 
> > addressable through dot notation like methods are but I can see why 
> > that wouldn't be quite right. This might be a better 
> question for the 
> > tutor list...)
> > 
> > Andy Baker
> 
> 
> 
> --
> Still searching for an even prime > 2!
> 




More information about the Python-list mailing list