At 07:04 PM 6/30/2006 -0400, Andrew Koenig wrote: >However, if I write > > def g(): > return x > x = 42 > g() > >the result is 42. With lexical scoping, I believe it should be undefined. > >The reason is that when the compiler encounters the definition of g, >variable x is not yet bound, and there is nothing in the body of g that >would bind it. Therefore, g requires a binding to exist at the time it is >compiled; because no such binding exists, this example would be an error (at >compile time) under lexical scoping.
That sounds like a bug, not a feature. It's frequently useful to have forward references in function bodies to names that are not yet globally bound, e.g. for classes, or mutually-recursive functions. _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com