[Python-Dev] Pickling Question

Patrick K. O'Brien pobrien@orbtech.com
Sat, 9 Nov 2002 08:46:55 -0600

On Saturday 09 November 2002 08:35 am, Guido van Rossum wrote:
> > I don't feel that this solution is entirely satisfactory and so I
> > thought I would ask (a bit late, I know) whether I am completely
> > correct in my assertions. If not, how else can this be handled. If
> > so, is there any chance of adding a better way to handle this
> > situation?
> >
> > [1] http://www-106.ibm.com/developerworks/library/l-pypers.html
> I don't believe a search-and-replace on a pickle can ever be safe. 
> In a binary pickle, it might interfere with length fields.  And in
> either kind of pickle, you might accidentally replace data that
> happens to look like a module name.

Yes. And that's why this was nagging me. I should have asked about it 

> I'd suggest something else instead: when you have a pickle
> referencing module A which has since been renamed to B, create a
> dummy module A that contains "from B import *".  Then load the
> pickle, and write it back again.  The loading should work because a
> reference to class A.C will find it (as an alias for B.C); the
> storing should store it as B.C because that's the real name of class

I like this. Wish I had thought of it. Thanks.

Patrick K. O'Brien
Orbtech      http://www.orbtech.com/web/pobrien
"Your source for Python programming expertise."