Skip to content

Instantly share code, notes, and snippets.

@ento
Created September 25, 2013 07:44
Show Gist options
  • Select an option

  • Save ento/6696347 to your computer and use it in GitHub Desktop.

Select an option

Save ento/6696347 to your computer and use it in GitHub Desktop.
is_picklable(obj)
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