Movatterモバイル変換
[0]ホーム
how to avoid importing the same module more than once?
Ixokainoone at nowhere.org
Tue Apr 10 04:11:48 EDT 2001
When Python encounters 'import foo', it first checks in sys.modules to seeif 'foo' has already been imported. If so, it basically just does thefollowing:foo = sys.modules['foo']You have to do that anyways, so that you'll have 'foo' to access in yourmodule... so there really is no problem with importing a module morethen once, the work only gets done once, and every other occassionis 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 messagenews: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-listmailing list
[8]ページ先頭