Basic Serialization - a design decision question

Terry Reedy tjreedy at udel.edu
Fri Apr 6 16:38:19 EDT 2007


"Gizmo" <gizmo1 at gmail.com> wrote in message 
news:5d2e4d280704060940s3fa1defdl874c8c4e7fa92266 at mail.gmail.com...
| Hello
| I am a relative newcomer to Python, and I am studying it to understand 
its
| design. It intrigues me.
| I recently studied Serialization of classes via the pickle/cPickle 
library,
| and I have a question.
|
| Why is Serialization handled by a separate library (ie, pickle). Is it
| possible, by design, to have serialization "internally" implemented via 
an
| implicit ___serialize___ method? Ofcourse, you have to make this method 
not
| overrideable (sp?). For example, the __repr__ method gives us the string
| representation of a class... similarly, the __serialize__ method would 
give
| us the "serial norm" representation of the class.

Pickle has the factored-out code common to all classes.  It uses 
.__reduce__() for each, which has the class-specific code.

| This would allow me to do something like this,
| conn.send(serial(myClass));  // or something like that?

I believe pickle does more than just that.

tjr







More information about the Python-list mailing list