How do I write to an ARFF file using the LIAC-ARFF package in Python?

I want to load an ARFF file in python, then change some values ​​and then save the changes to the file. I am using the package LIAC-ARFF

( https://pypi.python.org/pypi/liac-arff ). I have uploaded an ARFF file with the following lines of code:

import arff
data = arff.load(open(FILE_NAME, 'rb'))

      

After manipulating some values ​​internally data

, I want to write data

to another ARFF file. Any solution?

+3


source to share


1 answer


Use the following code:

import arff
data = arff.load(open(FILE_NAME, 'rb'))
f = open(outputfilename, 'wb')
arff.dump(data, f)
f.close()

      



In the description, LICA-ARFF

you see a method dump

that is serialized to a file, but this is wrong. It just writes the object as a text file. Serialization means storing the entire object, so the output file is binary, not text.

+3


source







All Articles