nested scopes
Nathaniel Gray
n8gray at caltech.edu.is.my.email.address
Mon Feb 5 05:01:58 EST 2001
Tim Peters wrote:
> Whether a name is local to a given scope is, in Python, determined by
> whether the name is *bound* somewhere in that scope. "import *" counts as
> a
> binding, but the compiler has no idea which names are being bound. So
> when compiling code for a nested function N, referencing a non-local name
> (one that is not bound to within N's body) X, the compiler has no idea
> which scope X belongs to if an "import *" (or "exec" stmt) appears in an
> enclosing
> function E. Any name whatsoever *may* become local in E then, but it's
> impossible to know anything about that at compile-time.
Interesting issue. What if the following was allowed:
>>> from tim_bot_module import tb*
telling the compiler that only names beginning with "tb" are imported.
This way you could still design libraries to use from ... import ..*
without totally throwing efficiency out the window. I know import * is
considered harmful, but occasionally (think tkinter) it's a useful
construct, assuming the library is designed to prevent name conflicts.
Just a thought,
-n8
--
_.~'^`~._.~'^`~._.~'^`~._.~'^`~._.~'^`~._
Nathaniel Gray
California Institute of Technology
Computation and Neural Systems
n8gray <at> caltech <dot> edu
_.~'^`~._.~'^`~._.~'^`~._.~'^`~._.~'^`~._
More information about the Python-list
mailing list