how to avoid importing the same module more than once?

Brian Quinlan BrianQ at ActiveState.com
Mon Apr 9 18:20:42 EDT 2001


Multiplying importing modules in Python is reasonably inexpensive. If Python
sees that the module has already been imported (by looking in sys.modules),
it does nothing.

-----Original Message-----
From: python-list-admin at python.org
[mailto:python-list-admin at python.org]On Behalf Of Graham Guttocks
Sent: Monday, April 09, 2001 3:08 PM
To: python-list at python.org
Subject: how to avoid importing the same module more than once?


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..

--
http://mail.python.org/mailman/listinfo/python-list





More information about the Python-list mailing list