Conditional based on whether or not a module is being used

Aahz aahz at pythoncraft.com
Tue Mar 16 19:51:23 EDT 2010


In article <ec8e0912-bc85-4c51-85f5-fc855e289c1c at k6g2000prg.googlegroups.com>,
Pete Emerson  <pemerson at gmail.com> wrote:
>
>Excellent, this is what I finally discovered, although I was looking
>for 'foo' in sys.modules.keys(), which apparently isn't necessary.

Actually, `foo in sys.modules.keys()` is double-slow, because first the
dict must be scanned to create a list, and then the list must be scanned
linearly to test for foo.
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

"Many customs in this life persist because they ease friction and promote
productivity as a result of universal agreement, and whether they are
precisely the optimal choices is much less important." --Henry Spencer



More information about the Python-list mailing list