Comments in pickles?

Emile van Sebille emile at fenx.com
Tue Jul 2 23:33:54 EDT 2002


"Roy Smith" <roy at panix.com> wrote in message
news:roy-AC514A.22260002072002 at reader2.panix.com...
> I've got a file parser that returns a data structure.  As part of a
> regression test suite, I'm going to parse several sample files and
save
> the resulting data structures as pickle files to compare against
future
> versions.  I want to check those pickles into CVS.
>
> Our usual practice is to imbed the CVS id string ($Id: ) in every
> checked-in file as a comment.  Is there any way to do that with a
> pickle?  Does a comment convention exist which cPickle.load()
> understands?

You could shadow the dumps and loads to add an attribute to each
non-slotted instance.
Here's a q&d for dumps for instance ;-)

import cPickle

class Test: pass

t = Test()
t.a = 1
t.b = 2

def cvsdumps(object, bin=0, dumps=cPickle.dumps):
    object._my_obscure_cvs_id_string_ = 'CVS_ID_STR'
    return dumps(object, bin)

cPickle.dumps = cvsdumps
cPickle.dumps(t)


You could also tweak the code the checks the pickles into cvs I imagine.

HTH,


--

Emile van Sebille
emile at fenx.com

---------




More information about the Python-list mailing list