2

I've got a class called instrument, with a bunch of methods and attributes defined.

When I pickle it, I was hoping it would pickle it complete with source etc, such that the entire class could be unpickled & used without the original source code.

pickle.dumps(Instrument)
Out[7]:
b'\x80\x03cinstrument\nInstrument\nq\x00.'

How can I get it to dump the whole thing?

cjm2671
  • 18,348
  • 31
  • 102
  • 161

1 Answers1

-1

From https://wiki.python.org/moin/UsingPickle

Generally you can pickle any object if you can pickle every attribute of that object. Classes, functions, and methods cannot be pickled -- if you pickle an object, the object's class is not pickled, just a string that identifies what class it belongs to. This works fine for most pickles (but note the discussion about long-term storage of pickles).

O Green
  • 17
  • 3