[Tutor] Re: Tutor digest, Vol 1 #634 - 13 msgs

Remco Gerlich scarblac@pino.selwerd.nl
Tue, 6 Mar 2001 12:02:38 +0100


On Tue, Mar 06, 2001 at 10:06:02AM -0000, alan.gauld@bt.com wrote:
> I am unsure, as to whether your answer really answers my question.  It
> depends upon how Python was designed. 
> 
> Yes and I admit I'm only passing on my understanding which is not intimate
> with 
> the internals but based on reading books and news articles...
> 
>   The fact that running bar.py produces 'hello from foo' in it does not make
> it certain that a pointer is not used and that Python simply follows the
> pointer to foo.py and puts it in.

It's a bit hard to read your mail since I think you're replying to a
personal mail, and I can't tell what was written by whom.

However, your explanation is similar to the way I believe importing works;
"import bar" does two things - 
1) *if* module 'bar' is not loaded yet (is not present in sys.modules) then
   it is loaded, and executed. So it's executed, but only once.
2) A reference 'bar' to the module is put into the current namespace.
   In case of 'from bar import *', the contents of bar are put into the
   namespace instead.
   
But why are we putting this in our own words, when you really want to know
how it works exactly you have to look at the Language Reference:
http://www.python.org/doc/current/ref/import.html

> Maybe a real guru could chip in here and tell us how it really works?
> cue Alex, Tim P, Remco et al?

I'm not a 'real guru' at all, just a CS student who likes Python a lot, but
I haven't even looked at internals... *You* wrote a book on it :-).

-- 
Remco Gerlich