Is there any way to return a function that will execute on the python side when returned? #5675
Answered
by
davidhewitt
varchasgopalaswamy
asked this question in
Questions
-
|
I have a feeling this would not be possible, but I wanted to check. Lets say I have a python function def add_units_to_array(array, units:str):
return array.with_units(units)and I have a Rust struct struct MyObject {
array: Array3<f64>
units: String
}
impl MyObject {
#[getter]
fn array_with_units(&self) {
/// What goes here?
}
}I would like to be able to do obj = Object(np.linspace(0,1,100), "cm")
obj.array_with_units # returns add_units_to_array(obj.array, obj.units)I assume obj.array_with_units() |
Beta Was this translation helpful? Give feedback.
Answered by
davidhewitt
Dec 5, 2025
Replies: 1 comment 1 reply
-
|
Looks like you need to find a way to get a reference to |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
varchasgopalaswamy
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Looks like you need to find a way to get a reference to
add_units_to_array(as f) and then usef.call1((self.array, self.units)). You could either pass that to theObjectconstructor or import it from wherever the Python code is.