Can local function access local variables in main program?

Sullivan WxPyQtKinter sullivanz.pku at gmail.com
Sat Nov 3 13:30:45 EDT 2007


Actually I am quite satisfied with and error, which is my expectation.
But the implicit global variable access seems quite uncomfortable to
me. Why is that necessary?

On Nov 3, 3:39 am, Stargaming <stargam... at gmail.com> wrote:
> On Sat, 03 Nov 2007 07:18:17 +0000, Sullivan WxPyQtKinter wrote:
> > I am confused by the following program:
>
> > def f():
> >     print x
> > x=12345
> > f()
>
> > result is:
>
> > 12345
>
> If python can't discover x in your current scope and you do not bind to
> it there, it will automatically access that global name x.




More information about the Python-list mailing list