import and scope inconsistency?

Heiko Wundram modelnine at ceosg.de
Mon Apr 4 06:50:34 EDT 2005


Am Montag, 4. April 2005 12:23 schrieb Jim:
> I can call MyFiles methods inside methods of the Brances classes.
> I cannot call Numeric methods inside methods of the Brances classes.
>
> 1. I was surprised I could call MyFiles methods in Branches methods.
> 2. Since I was used to using modules imported in the parent module I was
> surprised I couldn't use Numeric methods.

1. I can't answer you this one without looking at the actual code, but

2. You can never call any methods/classes which you imported in a "parent" 
module (actually, there's no such motion as parent module, as each module has 
its own namespace, and references to this namespace may appear anywhere else 
in another module).

In case this worked sometime ago and you didn't explicitly import the module 
in the "child" module, you silently did something like the following:

Mod1.py
-------

import Numeric
import Mod2

# Put the namespace (module object) in another namespace
Mod2.Numeric = Numeric

<blah>


Mod2.py
-------

<blah>


What you need for your simulation program is probably something like the 
following:

Simulation.py
-------------

import MyFiles
import Branches
import Numeric

print MyFiles.Branches is Branches # True
print MyFiles.Numeric is Numeric # True
print Branches.Numeric is Numeric # True


MyFiles.py
----------

import Branches
import Numeric

print Branches.Numeric is Numeric # True


Branches.py
-----------

import Numeric


HTH!

-- 
--- Heiko.
listening to: aenima_13_aenima.mp3
  see you at: http://www.stud.mh-hannover.de/~hwundram/wordpress/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20050404/c56de3c0/attachment.sig>


More information about the Python-list mailing list