import and scope inconsistency?

J

Jim

I would be very grateful for help on the following.

I have the following modules in a program. Names changed to protect the
innocent.

1.Simulation
2.Branches
3.MyFiles

I import Branches, Myfiles and the publicly available module Numeric
inside Simulation.

Branches and MyFiles both contain class definitions.

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.

What's going on?

Thanks
Jim O'Donnell
 
H

Heiko Wundram

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/

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQBCURv9f0bpgh6uVAMRArqpAJ934gNxmcJsFwUEswjdJ/fupC3CQgCdEKBS
ZONr0a90q5iQeqO46XWepXs=
=WQk5
-----END PGP SIGNATURE-----
 
H

Heiko Wundram

You're putting a Reply-To header in your posts to the mailing-list, but the
Reply-To address bounces.

Please correct: on't put in a Reply-To header, or at least put in some address
that doesn't bounce.

--
--- Heiko.
listening to: aenima_15_Third Eye.mp3
see you at: http://www.stud.mh-hannover.de/~hwundram/wordpress/

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQBCURxgf0bpgh6uVAMRAuvcAJ9FYHQKGmQ5ZvOhPQlUN05uNOnyrwCeMmon
Caju8HMcfsRkclA1yuJ0QQ0=
=VSHb
-----END PGP SIGNATURE-----
 
J

Jim

Heiko said:
You're putting a Reply-To header in your posts to the mailing-list, but the
Reply-To address bounces.

Please correct: on't put in a Reply-To header, or at least put in some address
that doesn't bounce.
Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
474,232
Messages
2,571,168
Members
47,803
Latest member
ShaunaSode

Latest Threads

Top