Skip to content

Instantly share code, notes, and snippets.

@depp
Created February 1, 2013 23:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save depp/4694889 to your computer and use it in GitHub Desktop.
Save depp/4694889 to your computer and use it in GitHub Desktop.
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