Skip to content

Commit

Permalink
ADD: example for importing dill using paker
Browse files Browse the repository at this point in the history
  • Loading branch information
desty2k committed Jul 1, 2021
1 parent 0b3f19f commit a7acd1e
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
48 changes: 48 additions & 0 deletions example/dill/dill.json

Large diffs are not rendered by default.

31 changes: 31 additions & 0 deletions example/dill/dill_example.py
@@ -0,0 +1,31 @@
"""
Example for importing dill from JSON file using paker.
If you have dill installed you should remove it by using `pip uninstall dill -y` command.
Note that `dill.tests` package was removed before dumping dill to .json.
"""

import paker


class SerializableClass:
pass


if __name__ == '__main__':
with paker.load(open("dill.json", "r")) as loader:
# dill can be imported only in this context
import dill

# create class instance
obj = SerializableClass()
setattr(obj, "attr", "This is string.")

dilled = dill.dumps(obj)
print("Serialized object is {}".format(dilled))
print("Deserialized object is {}".format(dill.loads(dilled)))

# import will throw error dill has been unloaded
try:
import dill
except ImportError as f:
print("dill unloaded successfullly!")

0 comments on commit a7acd1e

Please sign in to comment.