how to avoid importing the same module more than once?
Ixokai
noone at nowhere.org
Tue Apr 10 04:11:48 EDT 2001
When Python encounters 'import foo', it first checks in sys.modules to see
if 'foo' has already been imported. If so, it basically just does the
following:
foo = sys.modules['foo']
You have to do that anyways, so that you'll have 'foo' to access in your
module... so there really is no problem with importing a module more
then once, the work only gets done once, and every other occassion
is just binding a name to the already loaded module.
--Stephen
(replace NOSPAM with 'seraph' to respond via email)
"Graham Guttocks" <graham_guttocks at yahoo.co.nz> wrote in message
news:mailman.986854093.6675.python-list at python.org...
> Greetings,
>
> When breaking up a large program into several different modules, I'm
> wondering if there is any way to avoid importing the same global modules
> more than once, as I'm sure this is degrading performance.
>
> For example, if I have a program which uses the "os" built-in module
> and imports two custom modules which also use "os", then I end up
> running "import os" three times!
>
> Regards,
> Graham
>
>
____________________________________________________________________________
_
> http://movies.yahoo.com.au - Yahoo! Movies
> - Now showing: Dude Where's My Car, The Wedding Planner, Traffic..
>
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 80,000 Newsgroups - 16 Different Servers! =-----
More information about the Python-list
mailing list