'how do i make a automatic python file importer (in python)?

I am asking like a extensions, like there are like 3 files of python and you want to import it in, but you don't know their names, maybe its a self-made one or imported. What I want its like :

for i(python file) in file(location of folder that holds these python files):
    # i dont know how to import that file using import, so help me with that too
    import file(that file)


Solution 1:[1]

There are multiple ways to do this. Read the official python packaging documentation for all the gory details.

The most basic way is to iterate over pkgutil.iter_modules() to find the modules, then use importlib.import_module(name) to load them.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Sören