-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f664c36
commit 305bc9d
Showing
1 changed file
with
20 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# src/bo4e/bo/__init__.py | ||
import importlib | ||
import pkgutil | ||
|
||
# Iterate through all the modules in the current package | ||
package = __name__ | ||
for _, modname, _ in pkgutil.iter_modules(__path__, package + "."): | ||
# Import the module | ||
module = importlib.import_module(modname) | ||
# Iterate through the attributes of the module | ||
for attribute_name in dir(module): | ||
# Get the attribute | ||
attribute = getattr(module, attribute_name) | ||
# Check if the attribute is a class and it's defined in this module (not imported) | ||
if isinstance(attribute, type) and attribute.__module__ == module.__name__: | ||
# Add the class to the namespace of this module | ||
globals()[attribute_name] = attribute | ||
|
||
# Now you can directly import any class from the bo package | ||
# from bo4e.bo import Vertrag, Ansprechpartner, etc. |