Python Module Internal Representation and Introspection: Difference between revisions
Jump to navigation
Jump to search
Line 7: | Line 7: | ||
=The <tt>module</tt> Class= | =The <tt>module</tt> Class= | ||
All module instances are represented internally as instances of the <code>module</code> | All [[Python_Language_Modularization#Module_Internal_Representation_and_Introspection|module]] and [[Python_Language_Modularization#Package_Internal_Representation_and_Introspection|package]] instances are represented internally as instances of the <code>module</code> | ||
==Attributes== | ==Attributes== |
Revision as of 02:20, 4 January 2023
Internal
Overview
The module Class
All module and package instances are represented internally as instances of the module
Attributes
__file__
Once imported, the file associated with the module can be determined using the module object's __file__ attribute:
import mymodule
[...]
print(mymodule.__file__)
The directory portion of __file__
should be one of the directories in sys.path
.