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.

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top