When using the interactive shell in Spyder, for instance, all sorts of classes are in the global namespace, so it would be nice to be able to interactively find what module the class comes from.
Asked
Active
Viewed 66 times
0
-
http://stackoverflow.com/questions/7027848/getting-corresponding-module-from-function has a code example of doing this. – TheSoundDefense Jul 27 '14 at 00:06
-
See also https://stackoverflow.com/questions/2020014/get-fully-qualified-class-name-of-an-object-in-python, https://stackoverflow.com/questions/5271112/obtaining-module-name-x-module-vs-x-class-module, https://stackoverflow.com/questions/12569452/how-to-identify-numpy-types-in-python. – Ry- Jul 27 '14 at 00:06
-
You're right, it seems like there are several similar answers. Somehow in searching using the wording of my question, I did not find those. Perhaps for that small reason this question still has some value. – Michael Currie Jul 27 '14 at 00:22
1 Answers
0
The answer is buried in one of the responses to the hidden features of Python question:
You can ask any object which module it came from by looking at its
__module__
property. This is useful, for example, if you're experimenting at the command line and have imported a lot of things.Along the same lines, you can ask a module where it came from by looking at its
__file__
property. This is useful when debugging path issues.

Community
- 1
- 1

Michael Currie
- 13,721
- 9
- 42
- 58