Pass a mutable reference #4230
Answered
by
therealevahill
therealevahill
asked this question in
Questions
-
Hi, at first, thank your great work. It is really a pleasure to work with PyO3. I have one question, I did not find an answer for it. #[pyfunction]
fn foo(value: &mut u16) {
*value = 42;
} value = 0
foo(value)
print(value) # would expect to print 42 here. I tried lots of stuff with PyCell and Bound, but did not get it working. |
Beta Was this translation helpful? Give feedback.
Answered by
therealevahill
Jun 4, 2024
Replies: 1 comment 5 replies
-
You can't. Integers are immutable in Python, and Python does not support passing reference-to-variables in the way your example shows. |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Doing like this works: Thank you very much @alex