import X between submodules in a package
Bruno Desthuilliers
bruno.42.desthuilliers at wtf.websiteburo.oops.com
Wed Dec 19 07:58:50 EST 2007
Donn Ingle a écrit :
>> would be a VeryBadThing(tm).
> :)
>
>> Having explicits imports in each module is good wrt/ readability.
> Okay, I can accept that. I worry that it's opening the module file over and
> over again
Hopefully not ! "import" is not "include".
> - or does it open it once and kind of re-point to it when it
> hits a second import of the same thing?
You guess. When fisrt imported, the module's source is executed, a
module object is created and stored in sys.modules, and the needed names
are inserted into the importing module's namespace. Next times the
module is "served" directly from sys.modules.
>
>> package, you can of course factor them out in a distinct submodule and
>> just do a 'from myimports import *' at the top of the others submodules...
> Good point.
Note that while it's perfectly legal, that's a pattern I'd try to avoid
unless I have a very good reason to use it.
More information about the Python-list
mailing list