[Tutor] Add rownumber to list of .arff files

Daan Raemdonck daan.raemdonck at telenet.be
Sat Jan 15 18:02:49 CET 2011


Dear all,

 

I am reaching out to you because I have a small issue I need to deal with,
yet I feel that it requires pretty advanced coding to solve.

I have a whole lot of .arff files that would simply need a case number added
to every line of data.

I've been able to do this for 1 file, but now I need to extend the coding to
all files (as there are 100+ files).

 

I have pretty much all the coding, except for the last part of the puzzle,
being writing the data back to a file that takes the previous file name and
simply adds a prefix 'TRE'.

 

This is the code I have so far:

 

import os, glob

path = 'blablabla'

for infile in glob.glob( os.path.join(path, '*.arff') ):

                print "current file is: " + infile

                lines=infile.readlines()

                infile.close()

                outtext = ['%d %s' % (i, line) for i, line in
enumerate(lines)]

                outfile = open("TRE_previous file-name.arff","w")

                outfile.writelines(outtext)

                outfile.close()

 

Is there anyone who could give me some guidance on where to take it from
here?

 

Thanks in advance.

 

Sincerely,

Daan

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110115/bd012d87/attachment.html>


More information about the Tutor mailing list