[Tutor] Re: Tutor import
Charlie Clark
charlie@begeistert.org
Sat Apr 5 12:27:01 2003
On 2003-04-05 at 19:00:05 [+0200], tutor-request@python.org wrote:
> Message: 7
> From: Rob Brown-Bayliss <rob@zoism.org>
> To: PythonTutor List <tutor@python.org>
> Organization:
> Date: 05 Apr 2003 20:10:10 +1200
> Subject: [Tutor] generla import questions
>
>
> hi, I have a question about import.
>
> Say I have an app that does
>
> import a
> import b
> import c
>
> and some actual code.
>
> And in module b I have
>
> import c
>
> Are there now two copies of c in memory, are does all the class data and
> variables etc only exist once?
>
> Or put hit this way, if module c is:
The answer is think about the namespaces. If you do this in the interpreter
it will be easier and use dir()
"c" gets imported directly into your namespace and is thus directly
accessible
c.print "hi"
will do whatever "print" does in c
anything that is imported by "b" is available only in "b"
ie., b.c.print "hi" has to be used in this case. Confusion is pretty much
impossible except if you use "from b import *" in which case I think the
most recent object will be used. See the "diamond rule" on how this stuff
works in classes.
Charlie