By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,587 Members | 1,711 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,587 IT Pros & Developers. It's quick & easy.

import and scope inconsistency?

P: n/a
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
Jul 18 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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-----

Jul 18 '05 #2

P: n/a
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)

iD8DBQBCURxgf0bpgh6uVAMRAuvcAJ9FYHQKGmQ5ZvOhPQlUN0 5uNOnyrwCeMmon
Caju8HMcfsRkclA1yuJ0QQ0=
=VSHb
-----END PGP SIGNATURE-----

Jul 18 '05 #3

P: n/a
Jim
Heiko Wundram wrote:
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
Jul 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.