[Edu-sig] Function Question -- I'm confused...

agauld@crosswinds.net agauld@crosswinds.net
Wed, 19 Sep 2001 08:40:02 +0100


On 18 Sep 01, at 8:21, Christopher A. Craig wrote:
> > def foo():
> >    def bar():
> >        print "Hello from bar"
> >    bar()
> > In earlier versions of Python I think you could still type 
> > the code but bar would still be seen at the module level.
> 
> This example does not use nested scoping, and will work correctly
> Python 1.5

Yes, that's what I said. What I got totally wrong was the bit 
about bar being seen at module level. What I was thinking 
about was the fact that bar couldn't see the internals of 
foo because it was working effectively outside the scope 
of foo - at module level. But it is not in fact visible at 
module level - oops! Sorry folks.

> Nested scopes allow an embedded function to see the variables of its
> parent.  

Correct, that's what I got wrong.

No excuses, I just hit the reply button too fast and didn't think it 
through properly. Aplogies all.

Alan g