package pyml

  1. Overview
  2. Docs

General functions to handle Python values

The type of a Python value.

Structural comparison of values of type Py.Object.t rely on Python comparison of underlying values. That is to say, if u and v are two values of type Py.Object.t, and by abuse of notations, if we denote also u and v their respective value in Python, we have u = v in OCaml if and only if u == v in Python, and u < v in OCaml if and only if u < v in Python, etc.

Moreover, there are five values which are handled specially:

These values are guaranteed to be unique, so that the physical equality can be used to compare against their definitions: for instance, a value v of type Py.Object.t is None if and only if v == Py.none.

val del_attr : t -> t -> unit

Wrapper for PyObject_DelAttr

val del_attr_string : t -> string -> unit
val del_item : t -> t -> unit

Wrapper for PyObject_DelItem

val del_item_string : t -> string -> unit
val get_attr : t -> t -> t option

Wrapper for PyObject_GetAttr

val find_attr : t -> t -> t

Equivalent to get_attr but raises a Not_found exception in case of failure.

val find_attr_opt : t -> t -> t option

Alias for get_attr.

val get_attr_string : t -> string -> t option
val find_attr_string : t -> string -> t

Equivalent to get_attr_string but raises a Not_found exception in case of failure.

val find_attr_string_opt : t -> string -> t option

Alias for get_attr_string.

val get_item : t -> t -> t option

Wrapper for PyObject_GetItem

val find : t -> t -> t

Equivalent to get_item but raises a Not_found exception in case of failure.

val find_opt : t -> t -> t option

Alias for get_item.

val get_item_string : t -> string -> t option

get_item_string o key returns the element corresponding to the object key or None on failure.

val find_string : t -> string -> t

Equivalent to get_item_string but raises a Not_found exception in case of failure.

val find_string_opt : t -> string -> t option

Alias for get_item_string.

val get_iter : t -> t

Wrapper for PyObject_GetIter

val get_type : t -> t

Wrapper for PyObject_GetType

val has_attr : t -> t -> bool

Wrapper for PyObject_HasAttr

val has_attr_string : t -> string -> bool
val hash : t -> int64

Wrapper for PyObject_Hash

val is_true : t -> bool

Wrapper for PyObject_IsTrue

val not : t -> bool

Wrapper for PyObject_Not

val is_instance : t -> t -> bool
val is_subclass : t -> t -> bool
val print : t -> out_channel file -> unit

Wrapper for PyObject_Print

val repr : t -> t

Wrapper for PyObject_Repr

val rich_compare : t -> t -> compare -> t
val rich_compare_bool : t -> t -> compare -> bool
val set_attr : t -> t -> t -> unit

Wrapper for PyObject_SetAttr

val set_attr_string : t -> string -> t -> unit
val set_item : t -> t -> t -> unit

Wrapper for PyObject_SetItem

val set_item_string : t -> string -> t -> unit
val str : t -> t

Wrapper for PyObject_Str

val string_of_repr : t -> string

string_of_repr o returns the string repr o. We have Py.Object.to_string o = Py.String.to_string (Py.Object.repr o).

val to_string : t -> string

to_string o returns the string str o. We have Py.Object.to_string o = Py.String.to_string (Py.Object.str o).

val as_char_buffer : t -> string
val as_read_buffer : t -> string
val as_write_buffer : t -> string
val reference_count : t -> int

reference_count o returns the number of references to the Python object o.

val format : Format.formatter -> t -> unit

Py.Object.format fmt v is equivalent to Format.pp_print_string fmt (Py.Object.to_string v). Can be used as printer for the top-level: #install_printer Py.Object.format.

val format_repr : Format.formatter -> t -> unit

Py.Object.format_repr fmt v is equivalent to Format.pp_print_string fmt (Py.Object.string_of_repr v). Can be used as printer for the top-level: #install_printer Py.Object.format_repr.

val call_function_obj_args : t -> t array -> t
val call_method_obj_args : t -> t -> t array -> t
val call_method : t -> string -> t array -> t

Py.Object.call_method o m args is equivalent to Py.Object.call_method_obj_args o (Py.String.of_string m) args.

val call : t -> t -> t -> t

Wrapper for PyObject_Call

val size : t -> int

Wrapper for PyObject_Size

val dir : t -> t

Wrapper for PyObject_Dir

OCaml

Innovation. Community. Security.