Python Module Internal Representation and Introspection: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 9: Line 9:
All module instances are represented internally as instances of the <code>module</code>
All module instances are represented internally as instances of the <code>module</code>


=Attributes=
==Attributes==
==<tt>__file__</tt>==
===<tt>__file__</tt>===
Once imported, the file associated with the module can be determined using the module object's __file__ attribute:
Once imported, the file associated with the module can be determined using the module object's __file__ attribute:
<syntaxhighlight lang='python'>
<syntaxhighlight lang='python'>

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.