Python compare objects in C API -
given 2 pyobject*
s, how can compare them in c api?
i thought of a == b
@ first, it's incorrect since compare pointer , not object. i'm looking a == b
(not a b
) python equivalent in python c api.
you looking pyobject_richcompare
function:
pyobject *result = pyobject_richcompare(a, b, py_eq);
from documentation:
pyobject* pyobject_richcompare(pyobject *o1, pyobject *o2, int opid)
return value: new reference.
compare values of
o1
,o2
using operation specifiedopid
, must 1 ofpy_lt
,py_le
,py_eq
,py_ne
,py_gt
, orpy_ge
, corresponding<
,<=
,==
,!=
,>
, or>=
respectively. equivalent of python expressiono1 op o2
,op
operator correspondingopid
. returns value of comparison on success, ornull
on failure.
you might interested in pyobject_richcomparebool
function, same pyobject_richcompare
returns integer rather pyobject *
. specifically, 1
returned true, 0
false, , -1
error.
Comments
Post a Comment