Replies: 1 comment
-
I have found a way via pybind. I am just uncertain of the performance penalty if any that it incurs. Here is the solution I have found: auto some_fn {
py::object ValueError = py::module_::import("builtins").attr("ValueError");
auto err = ValueError( "blablabla" );
return err;
} Does that internally call the C API, or does it run the interpreter ? I am still trying to figure all this out. Sorry if the questions are a bit basic. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi.
In some python programming I do, I find it useful to return an error instead of raising it. Thus, I sometimes do:
Whether or not this is a bad practice (it might very well be considered bad practice), I was trying to port some of my code to pybind11, but I could not instantiate an error and return it. Since
pybind11::value_error
is a C++ error, when you return it to python, it rightfully complains that it got an object it doesn't know what to do with.I have looked into creating an object directly with the C API, but from my understanding after a few hours of looking at the python doc, reading on the C API and reading stack overflow answers, it does not seem straight forward without raising the exception (and I might/"hope to" be wrong).
Is something like that possible with pybind ? Could someone point me in the right direction ?
PS: This is my first steps with pybind11 and I want to congratulate anyone involved with it: I find it incredibly well done and the documentation very helpful. So thanks and congrats if you are reading this and are a contributor.
Beta Was this translation helpful? Give feedback.
All reactions