473,500 Members | 1,686 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

import and scope inconsistency?

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
3 1264
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
3088
by: didier.doussaud | last post by:
I have a stange side effect in my project : in my project I need to write "gobal" to use global symbol : .... import math .... def f() : global math # necessary ?????? else next line...
7
1847
by: cyberco | last post by:
I want to import a long list of modules in a separate thread to speed things up. How can I make the modules imported in that separate thread accessible outside the method? ...
6
1632
by: Emanuele D'Arrigo | last post by:
Hi everybody, in the small snippet of code below, you can see two identical debugMsg(this.myname) statements, one correctly returns "manu" but the other returns "undefined". This is due to...
7
2138
by: bambam | last post by:
import works in the main section of the module, but does not work as I hoped when run inside a function. That is, the modules import correctly, but are not visible to the enclosing (global)...
0
7134
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7180
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7229
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5485
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3108
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3103
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1429
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
667
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
311
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.