DMelt:IO/2 Java and Python IO

From jWork.ORG
Jump to: navigation, search
Limitted access. Reguest membership or login to this link first if you are already a member
Contents

Java and Python IO

Native Java IO classes

Read Java IO tutorial. Below we show a simple example of how to use Java classes using Python/Jython syntax for IO:

from java.io import *
fo=FileOutputStream('data.d')
out=DataOutputStream(BufferedOutputStream( fo ))
list=[1.,2.,3.,4.,5.]
for a in list:
   out.writeFloat(a)
out.close()
fo.close()

Native Python IO

Read Python IO tutorial. Below we show an example of how to write a list of numbers using the Python class "pickle" for IO:

>>> import pickle
>>> f=open('data.pic','w')
>>> pickle.dump([1,2,3,4],f)
>>> f.close()

I/O performance and benchmarks

Here we compare performance of the PFile and HFile classes for read and write mode. Benchmark results are given together with the code.

More information on this topic is in DMelt books