[Tutor] Add rownumber to list of .arff files

David Hutto smokefloat at gmail.com
Sat Jan 15 22:42:00 CET 2011


On Sat, Jan 15, 2011 at 12:02 PM, Daan Raemdonck
<daan.raemdonck at telenet.be> wrote:
> 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("%s%s"%('TRE',previousfilename,"w")
>
>                 outfile.writelines(outtext)
>
>                 outfile.close()
>

If you want to add it in seperately.
>
>
> Is there anyone who could give me some guidance on where to take it from
> here?
>
>
>
> Thanks in advance.
>
>
>
> Sincerely,
>
> Daan
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>



-- 
Sometimes...my mama...says I get over excited about technology.


More information about the Tutor mailing list