Python Module Internal Representation and Introspection: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 17: Line 17:
print(mymodule.__file__)
print(mymodule.__file__)
</syntaxhighlight>
</syntaxhighlight>
The directory portion of <code>__file__</code> should be one of the directories in <code>[[#sys.path|sys.path]]</code>.
The directory portion of <code>__file__</code> should be one of the directories in <code>[[Python_Language_Modularization#sys.path|sys.path]]</code>.

Revision as of 01:55, 4 January 2023

Internal

Overview

The module Class

All module 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.