Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ADD: example for importing dill using paker
- Loading branch information
Showing
2 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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!") |