package pyml

  1. Overview
  2. Docs

Module Py.ImportSource

Importing Modules

Sourceval add_module : string -> Object.t

Wrapper for PyImport_AddModule

Sourceval exec_code_module : string -> Object.t -> Object.t

exec_code_module name bytecode imports the module name compiled in bytecode. bytecode can be obtained with Py.Module.compile (you may also consider Py.Import.exec_code_module_from_string. Wrapper for PyImport_ExecCodeModule

Sourceval exec_code_module_ex : string -> Object.t -> string -> Object.t
Sourceval exec_code_module_from_string : name:string -> ?filename:string -> ?dont_inherit:bool -> ?optimize:optimize -> string -> Object.t

exec_code_module ~name ?filename ?dont_inherit ?optimize source_code compiles source_code and imports the resulting bytecode as module name. filename is equal to name by default and is used in error messages. dont_inherit and optimize are passed to Py.Module.compile for compiling source_code.

Sourceval get_magic_number : unit -> int64
Sourceval get_module_dict : unit -> Object.t
Sourceval import_frozen_module : string -> bool
Sourceval import_module : string -> Object.t

Wrapper for PyImport_ImportModule Note that Python memoizes imported module, so that you will get the same object if you import the same module twice. (GitHub issue #16)

let m = Py.Import.import_module "json"
and m' = Py.Import.import_module "json" in
assert (m = m')
Sourceval import_module_opt : string -> Object.t option

import_module_opt m imports the module m and returns the module object if the import succeeds:. in this case, it is equivalent to Some (import_module m). If the module is not found, i.e. if import_module raises a Python exception of class ModuleNotFoundError, then try_import_module returns None.

Sourceval try_import_module : string -> Object.t option
Sourceval import_module_ex : string -> Object.t -> Object.t -> Object.t -> Object.t
Sourceval import_module_level : string -> Object.t -> Object.t -> Object.t -> int -> Object.t
Sourceval reload_module : Object.t -> Object.t
OCaml

Innovation. Community. Security.