Legend:
Library
Module
Module type
Parameter
Class
Class type
Library
Module
Module type
Parameter
Class
Class type
General functions to handle Python values
type t = Pytypes.pyobject
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:
Py.null
: the value NULL
used in the Python API for error casePy.none
: the value None
;Py.Bool.t
: the value True
;Py.Bool.f
: the value False
;Py.Tuple.empty
: the value ()
.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
.
Wrapper for PyObject_DelAttr
val del_attr_string : t -> string -> unit
Wrapper for PyObject_DelAttrString
Wrapper for PyObject_DelItem
val del_item_string : t -> string -> unit
Wrapper for PyObject_DelItemString
Wrapper for PyObject_GetAttr
Equivalent to get_attr
but raises a Not_found
exception in case of failure.
Equivalent to get_attr
but raises a Python exception in case of failure.
Wrapper for PyObject_GetAttrString
Equivalent to get_attr_string
but raises a Not_found
exception in case of failure.
Equivalent to get_attr_string
but raises a Python exception in case of failure.
Alias for get_attr_string
.
Wrapper for PyObject_GetItem
get_item_string o key
returns the element corresponding to the object key
or None
on failure.
Equivalent to get_item_string
but raises a Not_found
exception in case of failure.
Equivalent to get_item_string
but raises a Python exception in case of failure.
Alias for get_item_string
.
Wrapper for PyObject_GetIter
Wrapper for PyObject_GetType
Wrapper for PyObject_HasAttr
val has_attr_string : t -> string -> bool
Wrapper for PyObject_HasAttrString
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
Wrapper for PyObject_IsInstance
Wrapper for PyObject_IsSubclass
val print : t -> out_channel file -> unit
Wrapper for PyObject_Print
Wrapper for PyObject_Repr
Wrapper for PyObject_RichCompare
Wrapper for PyObject_RichCompareBool
Wrapper for PyObject_SetAttr
Wrapper for PyObject_SetAttrString
Wrapper for PyObject_SetItem
Wrapper for PyObject_SetItemString
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
Wrapper for PyObject_AsCharBuffer
val as_read_buffer : t -> string
Wrapper for PyObject_AsReadBuffer
val as_write_buffer : t -> string
Wrapper for PyObject_AsWriteBuffer
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
.
Wrapper for PyObject_CallFunctionObjArgs
Wrapper for PyObject_CallMethodObjArgs
Py.Object.call_method o m args
is equivalent to Py.Object.call_method_obj_args o (Py.String.of_string m) args
.
Wrapper for PyObject_Call
val size : t -> int
Wrapper for PyObject_Size
Wrapper for PyObject_Dir