ASPN ActiveState Programmer Network  
ActiveState, a division of Sophos
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups
Submit Recipe
My Recipes

All Recipes
All Cookbooks


View by Category

Title: Pickle objects under jython
Submitter: Ferdinand Jamitzky (other recipes)
Last Updated: 2003/11/17
Version no: 1.0
Category: Jython

 

5 stars 1 vote(s)


Description:

Using the pickle module under jython is a rather slow method for storing data. Using the ObjectOutputStream speeds it up. You can save and restore objects (jython and java) with these functions.

Source: Text Source

from java import io
def saveObject(x,fname="jython.bin"):
    outs=io.ObjectOutputStream(io.FileOutputStream(fname))
    outs.writeObject(x)
    outs.close()
def loadObject(fname="jython.bin"):
    ins=io.ObjectInputStream(io.FileInputStream(fname))
    x=ins.readObject()
    ins.close()
    return x


x={1:1,'two':"2",'three':[1,2,3]}
saveObject(x)
y=loadObject()
print y

Discussion:

The objects have to implement the Serializable interface. Most of jython's classes do. It is also very useful together with the JNumeric package.



Add comment

Number of comments: 1

PythonObjectInputStream, eoghan murray, 2004/02/21
Should the Input Stream be a PythonObjectInputStream from org.python.util? I would love to see a recipe on using Java's RandomAccessFile with Jython Eoghan
Add comment



Highest rated recipes:

1. A simple XML-RPC server

2. Web service accessible ...

3. Wrapping template engine ...

4. Assignment in expression

5. SOLVING THE METACLASS ...

6. Povray for python

7. Calling Windows API ...

8. Generic filter logic ...

9. Function Decorators by ...

10. MS SQL Server log monitor




Privacy Policy | Email Opt-out | Feedback | Syndication
© 2006 ActiveState Software Inc. All rights reserved.