Created
September 25, 2013 07:44
-
-
Save ento/6696347 to your computer and use it in GitHub Desktop.
is_picklable(obj)
This file contains hidden or 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
| import cPickle as pickle | |
| def pickle_recursively(obj, depth=0): | |
| pad = ' ' * depth | |
| if isinstance(obj, dict): | |
| print pad, 'dict', obj.__class__ | |
| for k, v in obj.iteritems(): | |
| print pad, k | |
| pickle_recursively(v, depth + 1) | |
| elif isinstance(obj, list): | |
| print pad, 'list', obj.__class__ | |
| for v in obj: | |
| pickle_recursively(v, depth + 1) | |
| elif isinstance(obj, (str, unicode)): | |
| print pad, obj | |
| pickle.dumps(obj) | |
| else: | |
| print pad, obj | |
| pickle.dumps(obj) | |
| def is_picklable(obj, debug=False): | |
| if debug: | |
| pickle_recursively(obj) | |
| pickle.dumps(obj) | |
| return True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment