Pickling and unpickling objects: a working example #3398
ChristopherRabotin
started this conversation in
Show and tell
Replies: 1 comment
-
I think quickwit-oss/tantivy-py#97 might also be a nice real-world example of the above which notably also includes frozen classes. |
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
-
If you're looking to pickle and unpickle objects on the Python side, here's a method that works with PyO3 0.18+ (and possibly earlier versions too). I thought I would post this because I didn't find an easy way to handle this.
pythonize
package, cf. https://github.com/davidhewitt/pythonize/ and https://docs.rs/pythonizeSerialize
andDeseralize
on your object__getstate__
as follows to pickle your object__setstate__
as follows to unpickle your object:#[new]
function that can take no input arguments and still return a valid object. This could be done by implementingDefault
, or by doing something a bit more complicated like this:Finally, the following works in Python:
The above code lives in Nyx, a high fidelity astrodynamics library for mission design and orbit determination of spacecraft. The time management stuff (
Unit.Day * 1.0
) is from hifitime.Beta Was this translation helpful? Give feedback.
All reactions