+ 2
Is it possible to use isinstance method to check, whether an object is a module? 🐍
import math as example_module #This does not work: isinstance(example_module, module) #This have worked to do the task: type(example_module).__name__ == "module" Do modules have a hidden class? They still are objects.
1 Réponse
+ 4
Seb TheS
You will need to include the following line:
from types import ModuleType
Then you can use:
isinstance(example_module, ModuleType)
You might be interested in the output of this code:
https://code.sololearn.com/ca0N7rLP32TB/?ref=app