jeudi 21 février 2019

Importing modules from file path very slow Is there any solution for this?

I have a list of modules that should be imported automatically and in a dynanamic way. Here is a snippet from my code:

for m in modules_to_import:
    module_name = dirname(__file__)+ "/" +m
    spec = importlib.util.spec_from_file_location("package", module_name)
    imported_module = importlib.util.module_from_spec(spec)
    spec.loader.exec_module(imported_module)

I measured the time and it becomes slower and slower after each import. Is there some solution to this or why does it become slower? Thanks a lot!





Aucun commentaire:

Enregistrer un commentaire