Imports awareness in Imported modules problem

Mohamed Yousef harrrrpo at gmail.com
Sun Aug 24 00:29:09 CEST 2008


Hello ,

The problem I'm asking about is how can imported modules be aware of
other imported modules so they don't have to re-import them (avoiding
importing problems and Consicing code and imports )
Take Example :-
in A.py :-

import B
print dir() # no problems we can see B which contain re module and C module
B.C.W() # our problem here we get an empty list

in B.py :-

import re
import C

in C.py :-

def W():
	print dir()# when called from A we get [] though other imports has
been made to re and others

my goal is basically making W() aware of the re module when called from A
----
why am i doing this in the first place
I'm in the process of a medium project where imports of modules start
to make a jungle and i wanted all needed imports to be in a single
file (namely __init__.py)
and then all imports are made once and other modules feel it

another reason to do this that my project is offering 2 interfaces
(Console and GUI through Qt) and i needed a general state class (
whether i'm in Console or GUI mode) to be available for all , for
determining state and some public functions ,and just injecting
Imports everywhere seems a bad technique in many ways (debugging ,
modifying ...etc )

in PHP "Require" would do the trick neatly ... so is there is
something I'm missing here or the whole technique is bad in which case
what do you suggest

Thanks,

Regards,
Mohamed Yousef



More information about the Python-list mailing list