1----FILE_1----
2def mult(a, b):
3 return a * b
4
5----FILE_2----
6from FILE_1 import mult
7
8print(mult(2, 4))
9# >>> 8
1from inspect import isclass
2from pkgutil import iter_modules
3from pathlib import Path
4from importlib import import_module
5
6# iterate through the modules in the current package
7package_dir = Path(__file__).resolve().parent
8for (_, module_name, _) in iter_modules([package_dir]):
9
10 # import the module and iterate through its attributes
11 module = import_module(f"{__name__}.{module_name}")
12 for attribute_name in dir(module):
13 attribute = getattr(module, attribute_name)
14
15 if isclass(attribute):
16 # Add the class to this package's variables
17 globals()[attribute_name] = attribute
18