For example, I import json like so import json and now somewhere in the code I want to check if it has been imported. It should be something like: has_imported(module_name).
The reason why I'm asking this is because I'm trying to understand how pkgutil.walk_packages() works. It must import the modules it lists but for some reason some modules are not imported. Seems like I have to import them with a separate function but first this function needs to "know" whether a module that it gets as an argument was imported or not.
There are some similar questions, but I'm far from being satisfied with the answers.
import jsonat the top of your file, then you can be pretty sure it's imported in that file. That does not mean it will be imported everywhere (in other files). Might that be a cause of confusion here? Or are you trying to figure out whether any one package has generally been imported by any other module somewhere? (If so, what for?)pkgutil.walk_packages()works, why not just look at its source code?walk_packages(as far as I understand it imports modules on the fly) but some modules in the list don't seem to be imported. I'm just trying to figure out why,