[Python-Dev] intra-package mutual imports fail: "from <pkg> import <mod>"

Matthias Urlichs smurf@noris.de
Sun, 2 Jun 2002 19:45:06 +0200


Hi,

Gisle Aas:
> > What I meant to say was: Perl shares the actual symbol table slot when you
> > import something;
> 
> Wrong.  If you do:
> 
>    package Bar;
>    use Foo qw(foo);
> 
> Then you end up with \&Bar::foo and \&Foo:foo pointing to the same
> function object, but the symbol table slots are independent.

Right, actually; we're just miscommunicating.

Let's state it differently: the situation is more like "use Foo qw($foo)"
(you can't assign to &Foo::foo). 

After the "use", \$Bar::foo and \$Foo:foo point to the same scalar
variable, thus $Foo::foo and $Bar::foo are the same variable and no longer
independent (unless a different scalar or glob reference is stored in
to *Foo::foo, but that's too much magic for a FAQ entry).

In Python, Bar.foo gets set to the contents of Foo.foo when the import
statement is processed, but the two variables are otherwise independent.

-- 
Matthias Urlichs     |     noris network AG     |     http://smurf.noris.de/