how does import work ?
Michele Simionato
mis6 at pitt.edu
Wed Nov 20 14:59:24 EST 2002
Alex Martelli <aleax at aleax.it> wrote in message news:<laNC9.31997$744.1183146 at news1.tin.it>...
> Michele Simionato wrote:
> ...
> > Suppose now I import ONLY the function f2, but not f1:
> >
> >>>> from f1f2 import f2
>
> That's basically equivalent to:
> import f1f2
> f2 = f1f2.f2
> del f1f2
> except that if you already had an f1f2 identifier it's not disturbed.
>
> > therefore Python has imported f1 too, but is some hidden way, since
> > f1 is not in the current namespace dictionary:
>
> Of course not, but it's in sys.modules['f1f2'] 's namespace, right
> where it should be.
>
> > This behavior is quite confusing to me, somebody can explain what is
> > happening ?
>
> HTH...
>
>
> Alex
Thanks, now it is clear.
Michele
More information about the Python-list
mailing list