문제

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