[FRPythoneers] re: Pickling objects into a file

Sue Giller sag at hydrosphere.com
Tue Oct 9 17:16:12 MDT 2001


Here is a simple script that demonstrates my problem.  My output for 
a good pass is:

Numeric:  20.1.0
cPickle:  1.71
pickling  c:\python21\scripts\pickle\simple1.pck
unpickling  c:\python21\scripts\pickle\simple1.pck
[1  2  3  4 ]

If you then change the pickle flag to 0, and run the script in a new 
session, I get a GPF on the load call.

---CODE---
# simple test for pickling problem
import Numeric
import cPickle

basePath = "c:\\python21\\scripts\\pickle\\"

print "++++++"
# create a simple array of object, populated by integer data
ds1 = Numeric.array([1,2,3,4], 'O')
print "Numeric: " , Numeric.__version__
print "cPickle: ", cPickle.__version__
pickle = 1      # change to 0 to skip the pickling step
for ii in (range(1,2)):
    if pickle:
        fileName = "%s%s%d%s" % (basePath, "simple", ii, ".pck")
        print "pickling ", fileName
        fp = open(fileName, 'wb')
        cPickle.dump(ds1, fp, 1)
        fp.close()
    
for ii in range(1,2):
    fileName = "%s%s%d%s" % (basePath, "simple", ii, ".pck")
    print "unpickling ", fileName
    fp = open(fileName, 'rb')
    obj = cPickle.load(fp)      
    fp.close()
    print obj


> Which version of Numeric are you using?  A similar problem was solved
> a release or two ago. (Check the Numeric Archives at
> http://www.geocrawler.com/lists/3/SourceForge/1329/0/)
> 
> -- 
> Joe VanAndel  	          
> National Center for Atmospheric Research
> http://www.atd.ucar.edu/~vanandel/
> Internet: vanandel at ucar.edu
> _______________________________________________
> This message sent by the FRPythoneers mailing list.
> Unsubscribe: echo unsubscribe |
> FRPythoneers-request at lists.community.tummy.com URL:
> http://lists.community.tummy.com/mailman/listinfo/frpythoneers





More information about the FRPythoneers mailing list