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

Remco Gerlich scarblac at pino.selwerd.nl
Tue Mar 6 02:57:38 EST 2001


Robin Becker <robin at jessikat.fsnet.co.uk> wrote in comp.lang.python:
> In article <mailman.983806269.21732.python-list at python.org>, Thomas
> Wouters <thomas at xs4all.net> writes
> >
> ....
> >> 
> >> 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.
> 
> it isn't necessary in function namespaces either it's desirable to help
> the compiler and apparently now required to enforce the constant scope
> requirement.

Consider:

x=1

def whee():
   print x
   from spam import *

Does whee() give an error? Maybe. If there is a x in spam, then x is a
local variable, so 'print x' gives a NameError. If there isn't, then x is
the global, so print x is ok. Unfortunately it is not possible to know this
on time...

Causality loops. Some problems like this probably become even stranger with
nested scopes...

-- 
Remco Gerlich



More information about the Python-list mailing list