+ 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.

28th Aug 2019, 7:42 AM
Seb TheS
Seb TheS - avatar
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
29th Aug 2019, 7:01 AM
David Carroll
David Carroll - avatar