My python project has the following file structure:
/main.py
/functions
/functions/func1.py
/functions/func2.py
/functions/func3.py
/funcitons/__init__.py
Every func.py file has a variable ‘CAN_USE’. In some files it’s true in other false.
How can I check inside of my main.py which func.py files has ‘CAN_USE’ variable equals true?
Using
pkgutilyou can find all modules in a package:Note that this also checks other modules in your package (e.g.
__init__.py). You can filter them out in your loop if you want to (e.g.if not name.startswith('func'): continue).