(Important: see update below.)
I am trying to write an import_something function that will be important for specific modules. (No matter what this refers to.) The fact is that I would like these modules to be imported at the level from which the function is being called. For instance:
import_something()
Is it possible?
Update:
Sorry, my original phrase and example were misleading. I will try to explain my whole problem. I have a package in which there are several modules and packages. In __init__.py I want to import all modules and packages. Therefore, somewhere else in the program, I import the entire package and iterate over the modules / packages that it imported.
(Why? The package is called crunchers , and all types of crunchers are defined inside it, for example CruncherThread , CruncherProcess , and in the future MicroThreadCruncher possible. I want the crunchers package to automatically have all the clusters that are in it, so later in the program, when I use crunchers , I know that he can determine exactly which boxes he defined.)
I know that I can solve this problem, if I will not use functions at all, and do all the imports at the main level using for loops, etc. But this is ugly, and I want to see if I can avoid it.
If something else is unclear, ask in the comments.
source share