Skip to content

Instantly share code, notes, and snippets.

@salrashid123
Created February 18, 2023 12:46
Show Gist options
  • Save salrashid123/545c8e8b2b07746fdb8c2a15805ef242 to your computer and use it in GitHub Desktop.
Save salrashid123/545c8e8b2b07746fdb8c2a15805ef242 to your computer and use it in GitHub Desktop.
python dill example serialization
#!/usr/bin/python
import dill
# to serialize, uncomment
# class RCE:
# import os
# def __init__(self, v="foo"):
# self._v = v
# def sq(self, n):
# return n*n
# with open('p.bin', 'wb') as s:
# dill.dump(RCE(), s)
# to deserialize, comment the steps above and run
with open("p.bin", mode='rb') as s:
r = dill.load(s)
print(repr(r))
print(r.sq(2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment