To demonstrate the problem I have written the following program:

___________________________________  Code Start
________________________________
import pickle

destruct=1

class PickleTest:
        library={}

        def __init__(self):
                self.unpickle()
        def __del__(self):
                if destruct:
                        print "Pickling from destructor..."
                        self.pickle()

        def unpickle(self):
                try:
                        f=open("pickle.txt")
                        self.library=pickle.load(f)
                        f.close()
                        print "Unpickled just fine"
                except:
                        print "Error unpickling"
                        self.library={u"A": 1,
                                                  u"B": 2,
                                                  u"C": 3}

        def pickle(self):
                f=open("pickle.txt","w")
                pickle.dump(self.library,f)
                f.close()
                print "Pickled just fine"

if __name__=="__main__":
        pt=PickleTest()
        if not destruct:
                print "Pickling from __main__..."
                pt.pickle()
___________________________________ Code End
________________________________

Running the program with "pickle.txt" not created and destruct=1
generates the following output:

Error unpickling
Pickling from destructor...
Exception exceptions.LookupError: 'unknown encoding: raw-unicode-
escape' in <bound method PickleTest.__del__ of <__main__.PickleTest
instance at 0xb7d3decc>> ignored

If I now change destruct to 0 the output is:

Error unpickling
Pickling from __main__...
Pickled just fine

Even more odd is that with an existing "pickle.txt" and destruct set
to 1 it seems to work correctly:

Unpickled just fine
Pickling from destructor...
Pickled just fine



I'm running Python 2.5.4 on Debian Sid.

If anybody understands the error please enlighten me.

Dan
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to