[pypy-dev] how can i pickle an application-level object from interpreter code?

Armin Rigo arigo at tunes.org
Sat Oct 3 01:30:29 CEST 2009


Hi Philip,

On Fri, Oct 02, 2009 at 09:35:30AM -0700, Philip Guo wrote:
> I'm brand-new to PyPy, and here is my question: I want to selectively pickle
> Python objects that appear in application-level code, from *within* the
> interpreter.

What about writing a metaclass and keeping it all as portable, regular
Python code?  E.g.

    class MetaPickle(type):
        def __call__(self, *args, **kwds):
            x = type.__call__(self, *args, **kwds)
            pickle.dump(x, f)
            return x

    class X(object):
        __metaclass__ = MetaPickle

There are also ways to do it by patching the classes without changing
anything to their definition.  If you need more information about these
solutions, please ask in a general Python list.


A bientot,

Armin



More information about the Pypy-dev mailing list