Imports awareness in Imported modules problem

M

Mohamed Yousef

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
 

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top