Skip to content

Instantly share code, notes, and snippets.

@andresriancho
Created March 17, 2015 01:14
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andresriancho/15b5e226de68a0c2efd0 to your computer and use it in GitHub Desktop.
Save andresriancho/15b5e226de68a0c2efd0 to your computer and use it in GitHub Desktop.
Pickle debug
def debug_pickle(instance):
"""
:return: Which attribute from this object can't be pickled?
"""
attribute = None
for k, v in instance.__dict__.iteritems():
try:
cPickle.dumps(v)
except:
attribute = k
break
return attribute
@Jendker
Copy link

Jendker commented Sep 4, 2019

Version for Python3

import _pickle


def debug_pickle(instance):
    """
    :return: Which attribute from this object can't be pickled?
    """
    attribute = None

    for k, v in instance.__dict__.items():
        try:
            _pickle.dumps(v)
        except:
            attribute = k
            break

    return attribute

@andresriancho
Copy link
Author

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment