Skip to content

Instantly share code, notes, and snippets.

@jtprince
Last active August 29, 2015 14:06
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 jtprince/728377e2308c60693931 to your computer and use it in GitHub Desktop.
Save jtprince/728377e2308c60693931 to your computer and use it in GitHub Desktop.
dynamically include all files in folder with the package (and alternatively import each of those source files)
import os
_python_source_files = list(
filter(
lambda basename: basename.endswith(".py") and
not basename.startswith('_'),
os.listdir( os.path.dirname(os.path.realpath(__file__)) )
)
)
__all__ = [fn[:-3] for fn in _python_source_files]
del _python_source_files
# uncomment below if you want to import the submodules into the package namespace
# NOT sure if the blow works properly, but above works
# for mod in __all__: __import__(mod)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment