Autoloading means the automatic loading of the files required for your module. That is including the files required for your application without explicitly including each file with from modulename import filename
construct.
- let directory struct be like
main.py
project_dir/
|-- example.py
|-- README.md
|-- setup.py
|-- test_package
| |-- __init__.py
| |-- package_file_0.py
| |-- package_file_1.py
| |-- package_file_2.py
- and code
"""example.py"""
from test_package import package_file_0
from test_package import package_file_1
...
from test_package import package_file_n
but we are too lazy to type a lot letters
- install
pip install -U import-autoload
- add two lines to
__init__.py
"""__init__.py"""
from autoload import autoload
__all__ = autoload()
"""example.py"""
from test_package import *
- or variant
"""main.py"""
from autoload import autoload
autoload("project_dir.test_package", pattern="package_file_[0123]")
module_name
path to module dir with dot separator, like infrom module_name import
, default current modulepattern
like infnmatch(filename, pattern)
, default*.py
- seems to require python version >= 3.4. if you were able to test an early version, please contact me
- checks path to module and call
importlib.import_module()
- It's opensource and free software, see the LICENSE for more details
- import-export
- another autoloader
- handle system path separator for module_name