the demise of 'from foo import * and its implications?

Thomas Wouters thomas at xs4all.net
Mon Mar 5 10:30:41 EST 2001


On Mon, Mar 05, 2001 at 01:00:07AM +0000, Robin Becker wrote:
> In article <mailman.983746566.27513.python-list at python.org>, Jeremy
> Hylton <jeremy at alum.mit.edu> writes
> >>>>>> "RB" == Robin Becker <robin at jessikat.fsnet.co.uk> writes:
> >
> >  RB> my preference would be that statements legal in one context
> >  RB> should be legal in another where they make sense. I cannot see
> >  RB> how using import * or eval etc in nested scopes is somehow
> >  RB> obviously bad or different from the same usage in non-nested
> >  RB> scopes. The fact that the prohibition comes from making things
> >  RB> easier for the compiler adds to my confusion.
> >
> >Using import * in function's is asking for trouble, because it makes
> >it impossible for someone reading the code to know what a variable
> >refers to.  Consider this hypothetical bit of code:
> >
> >    from string import *
> >
> >    def f(x):
> >        from amodule import *
> >        return strip(x)
> >
> ....
> 
> doesn't from foo import * make things hard to locate at the global level
> as well? exec/eval/import can always do this surely.

The global namespace is a 'last call' namespace. The compiler doesn't (and
can't, since you can modify global namespaces from outside the namespace)
keep track of global names because it isn't necessary. Neither is true for
function namespaces.

-- 
Thomas Wouters <thomas at xs4all.net>

Hi! I'm a .signature virus! copy me into your .signature file to help me spread!




More information about the Python-list mailing list