From 5a6aa491056046dc8d828d7234873fecbdae8492 Mon Sep 17 00:00:00 2001 From: Wenzel Jakob Date: Wed, 13 Apr 2016 22:48:05 +0200 Subject: [PATCH] Added len() function --- include/pybind11/pytypes.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/include/pybind11/pytypes.h b/include/pybind11/pytypes.h index 455d8931..e23df9a7 100644 --- a/include/pybind11/pytypes.h +++ b/include/pybind11/pytypes.h @@ -461,4 +461,11 @@ public: } }; +inline size_t len(handle h) { + ssize_t result = PyObject_Length(h.ptr()); + if (result < 0) + pybind11_fail("Unable to compute length of object"); + return (size_t) result; +} + NAMESPACE_END(pybind11)