Domanda

Is there a function in Boost::Python that lets you get the hash of a boost::python::object, a.k.a the equivalent of Python's hash function? I've been reading the docs, but it doesn't seem to mention anything.

È stato utile?

Soluzione

hash in python is implemented with PyObject_Hash on the C side of things. If you have a random object obj, you can simply call:

long hash = PyObject_Hash(obj.ptr())

The ptr() method on a boost::python::object returns a PyObject * that has a borrowed reference to that object.

In general, there's tons of stuff in the CPython API that is not wrapped by boost::python. It's easy enough to just call it directly.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top