cpython-3.3.0: Bindings for libpython

Safe HaskellNone

CPython.Types.Module

Synopsis

Documentation

new :: Text -> IO ModuleSource

Return a new module object with the __name__ attribute set. Only the module’s __doc__ and __name__ attributes are filled in; the caller is responsible for providing a __file__ attribute.

getDictionary :: Module -> IO DictionarySource

Return the dictionary object that implements a module’s namespace; this object is the same as the __dict__ attribute of the module. This computation never fails. It is recommended extensions use other computations rather than directly manipulate a module’s __dict__.

getName :: Module -> IO TextSource

Returns a module’s __name__ value. If the module does not provide one, or if it is not a string, throws SystemError.

getFilename :: Module -> IO TextSource

Returns the name of the file from which a module was loaded using the module’s __file__ attribute. If this is not defined, or if it is not a string, throws SystemError.

addObject :: Object value => Module -> Text -> value -> IO ()Source

Add an object to a module with the given name. This is a convenience computation which can be used from the module’s initialization computation.

addIntegerConstant :: Module -> Text -> Integer -> IO ()Source

Add an integer constant to a module. This convenience computation can be used from the module’s initialization computation.

addTextConstant :: Module -> Text -> Text -> IO ()Source

Add a string constant to a module. This convenience computation can be used from the module’s initialization computation.

importModule :: Text -> IO ModuleSource

This is a higher-level interface that calls the current “import hook” (with an explicit level of 0, meaning absolute import). It invokes the __import__() computation from the __builtins__ of the current globals. This means that the import is done using whatever import hooks are installed in the current environment.

This computation always uses absolute imports.

reload :: Module -> IO ModuleSource

Reload a module. If an error occurs, an exception is thrown and the old module still exists.