Could someone provide me with a good way of importing a whole directory of modules? I have a structure like this:
/Foo bar.py spam.py eggs.py
Anurag's example with a couple of corrections:
import os, glob modules = glob.glob(os.path.join(os.path.dirname(__file__), "*.py")) __all__ = [os.path.basename(f)[:-3] for f in modules if not f.endswith("__init__.py")]