You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After compiling the code, if I ask for the length of the enumeration, I will get this error:
>>> len(Kind)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: object of type 'pybind11_type' has no len()
Any ideas how I can allow my python users to have len() for the exposed enumerations? I am using Pybind11 version 2.10.1 on Visual Studio 2019 (C++17).
Update 1: Even if I set the the magic method as an attribute like this (as proposed by other solutions), the problem is still the same:
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Suppose that I have a C++ enumeration like this:
enum class Kind {Kind1 = 1, Kind2, Kind3};
to bind this enumeration into a Python enumeration using Pybind11, I am doing something like this:
After compiling the code, if I ask for the length of the enumeration, I will get this error:
Any ideas how I can allow my python users to have len() for the exposed enumerations? I am using Pybind11 version 2.10.1 on Visual Studio 2019 (C++17).
Update 1: Even if I set the the magic method as an attribute like this (as proposed by other solutions), the problem is still the same:
Beta Was this translation helpful? Give feedback.
All reactions