Good news.  I tried pickling with "cPickle" and it works for pickling
dictionaries and classes where "pickle" didn't.  I guess this arises
from the fact that per the documentation, "cPickle can be up to 1000
times faster than pickle because the former is implemented in C." If
anyone can expound on this great.  But for now I'm very pleased that
pickling is supported on pythonCE with wxPython.

Here's my updated test code,

*pickleDump.py*

import cPickle as pickle
import traceback, sys

"""

    This test works on PythonCE 2.3.4, the most recent version of
    PythonCE for which I've found wxPython compiled.

"""

class cdata:
    """

        This class emulates the data class I was originally trying
        to pickle.  Although pickle didn't seem to work for classes
        or dictionaries, cPickle worked for both.  I had to
        include the instance class in the load module in order to unpickle
        the pickled instance data.

    """
    def __init__(self, x):
        self.data = x

f = open('test.txt','w')
error = open('dump_error.txt','w')
sys.stderr = error
log = open('dump_out.txt','w')
sys.stdout = log

#var = [n for n in range(10)]
var = {'parm1':1, 'parm2':'2a'}

try:
    tdata = cdata(var)
    print tdata.__dict__['data']
    pickle.dump(tdata,f)
    print 'Pickled dumped OK in,', __file__
except:
    traceback.print_exc()
    print 'Pickle dump failed! in', __file__

f.close()


*pickleLoad.py*

import cPickle as pickle
import sys, traceback

class cdata:
    """

        This class emulates the data class I was originally trying
        to pickle.  Although pickle didn't seem to work for classes
        or dictionaries, cPickle worked for both.  I had to
        include the instance class in the load module in order to unpickle
        the pickled instance data.

    """
    def __init__(self, x):
        self.data = x

e = open('load_error.txt','w')
sys.stderr = e
s = open('load_out.txt','w')
sys.stdout = s

try:
    f = open('test.txt','r')
    var = pickle.load(f)
    print 'Pickle loaded OK in,', __file__
    print var.data
except:

    traceback.print_exc()
    print 'Pickle not loaded in,', __file__
_______________________________________________
PythonCE mailing list
PythonCE@python.org
http://mail.python.org/mailman/listinfo/pythonce

Reply via email to