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 specified opid, must 1 of py_lt, py_le, py_eq, py_ne, py_gt, or py_ge, corresponding <, <=, ==, !=, >, or >= respectively. equivalent of python expression o1 op o2, op operator corresponding opid. returns value of comparison on success, or null 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

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -