Skip to content

Commit

Permalink
🎨 Use dynamical import
Browse files Browse the repository at this point in the history
  • Loading branch information
hf-krechan committed Dec 22, 2023
1 parent f664c36 commit 305bc9d
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/bo4e/bo/__init__.py
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.

0 comments on commit 305bc9d

Please sign in to comment.