Python Module Internal Representation and Introspection

From NovaOrdis Knowledge Base
Revision as of 01:54, 4 January 2023 by Ovidiu (talk | contribs) (→‎__file__)
Jump to navigation Jump to search

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.