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
I am facing an issue while working on a project that involves passing an std::string attribute from a C++ class to Python using pybind11. Specifically, I am attempting to use def_readwrite to create a Python wrapper for this attribute with read-write access.
The name attribute is of type std::string, and I intend to make it accessible in Python with read-write capabilities. However, I am encountering an error message: "SystemError: Negative size passed to PyUnicode_New." when I try to print the entity.name, print(entity.name)
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
-
Hi there!
I am facing an issue while working on a project that involves passing an
std::string
attribute from a C++ class to Python usingpybind11
. Specifically, I am attempting to usedef_readwrite
to create a Python wrapper for this attribute with read-write access.Here is a snippet of my code:
The name attribute is of type std::string, and I intend to make it accessible in Python with read-write capabilities. However, I am encountering an error message: "SystemError: Negative size passed to PyUnicode_New." when I try to print the entity.name,
print(entity.name)
Is it normal, how do I fix it?
I searched lots of pages including this one https://pybind11.readthedocs.io/en/stable/advanced/cast/strings.html but I couldn't find an answer to my problem.
Thank you in advance!
Beta Was this translation helpful? Give feedback.
All reactions