Created
February 1, 2013 23:22
-
-
Save depp/4694889 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os, time | |
def list_modules(path): | |
for name in os.listdir(path): | |
base, ext = os.path.splitext(name) | |
if '.' in base or base.startswith('__'): | |
continue | |
if ext == '.py': | |
yield base | |
elif not ext: | |
if not os.path.exists(os.path.join(base, '__init__.py')): | |
continue | |
yield base | |
c1 = time.time() | |
n = 0 | |
for mod in list_modules('/usr/local/lib/python3.2'): | |
n += 1 | |
__import__(mod) | |
c2 = time.time() | |
print('{} modules imported in {} seconds'.format(n, c2 - c1)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment