-
Notifications
You must be signed in to change notification settings - Fork 784
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expose PyEval_EvalCodeEx e.g. as Python::run_ex #2281
Comments
Can you expand on your use case for this? I wonder what the right api for this will be, because I really don't want to have functions with that many arguments. |
I am trying to (indirectly) run code that is accessing Personally I only care about |
Couldn't you just modify |
Good point. I guess I'd just inject |
Still, I don't think it'd be a bad idea to implement this at least partially? One thing that is annoying about the workaround above is that it changes line numbers around. |
We are possibly discussing different things. I did not mean to prepend this to the source, but to modify the Python::with_gil(|py| {
let sys = py.eval("__import__('sys')", None, None).unwrap();
py_run!(py, sys, "sys.argv = ['whatever']");
});
Python::with_gil(|py| {
py.eval("print(__import__('sys').argv)", None, None).unwrap();
}); I think as this is state of the |
Looks like that works, thanks! I still think there are use cases for implementing a |
Since the workaround is actually more general (being able to express arbitrary preparations instead of just patching up Therefore, I would prefer to not add to PyO3's API surface without a definite requirement. |
For the sake of throwing ideas into the ring, I'd be happy to hear proposals of what an implementation of a builder pattern would look like for this. I've always found the A more flexible pattern with extended and clearer functionality would be welcome. Similarly I'm not keen for |
Sounds good, I'll work on adding a builder. That being said, can you please provide a bit of guidance on the original error message I posted, i.e.:
|
Looks like it should actually be The easiest way to get one would be to start with |
I have a use-case where I need to evaluate some code and set args. It would be possible by exposing
PyEval_EvalCodeEx
e.g. as aPython::run_ex
method. Or perhaps call itrun_with_args
?I am trying to implement it myself for contribution to pyo3, but I am a little stuck on the correct method signature and type conversions. Here is what I have so far. It is mostly just copied from
Python::run_code
:The error at the
args
line looks like this:It seems like I am passing a pointer to the tuple object, but the method is expecting an array of the tuple elements?
A bit of guidance would be appreciated :)
The text was updated successfully, but these errors were encountered: