package pyml

  1. Overview
  2. Docs

Importing Modules

val add_module : string -> Object.t

Wrapper for PyImport_AddModule

val 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

val exec_code_module_ex : string -> Object.t -> string -> Object.t
val 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.

val get_magic_number : unit -> int64
val get_module_dict : unit -> Object.t
val import_frozen_module : string -> bool
val 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')
val 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.

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