On Sun, Aug 24, 2008 at 5:54 AM, Patrick Maupin <[EMAIL PROTECTED]> wrote:
> On Aug 23, 7:27 pm, "Mohamed Yousef" <[EMAIL PROTECTED]> wrote:
>
>> 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 )
>
> You could import sys and look at sys.modules

no even if you imported sys or used dir you will see no re in W() from
A . and you can even try to use re and will see

>> 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
>
> This doesn't sound like a good idea.  If A imports a module which is
> automatically imported into B's namespace, that sounds like a
> maintenance nightmare.
why ?
this saves time and consices whole package imports in one file
and maintaining it is easier (eg. you will never have circuular imports)
>>
>> 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 )
>
> I still don't understand.
put it another way a general variable in all modules
and some functions visible in all modules
>> 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 ?
>
> I don't know what to suggest, in that you haven't yet stated anything
> that appears to be a problem with how Python works.  If two different
> modules import the same third module, there is no big performance
> penalty.  The initialization code for the third module is only
> executed on the first import, and the cost of having the import
> statement find the already imported module is trivial.

it's not performance it's the jungle resulting
many imports in every file and suppose i changed the module used in
all modules name
guess what , it will have to be renamed in every import to it in all modules
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to