Conditional based on whether or not a module is being used

Aahz aahz at
Wed Mar 17 00:51:23 CET 2010

In article <ec8e0912-bc85-4c51-85f5-fc855e289c1c at>,
Pete Emerson  <pemerson at> 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           <*>

"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