Friday 15 March 2013

add new digits to a column of a text file in Python -


I'm trying to edit some text files I have to add value to one of the columns. I would like to add two new points to the second column of my files where the location is different. The first column will end on 13 characters, then there are two places and then you can add new two points and the other columns will remain without changes.

I have written the following script but unfortunately it works. I am grateful if someone can help me find my fault.

 % ******** function ************ def add_num (infile, outfile): Production = [ "% s% s% s "% (item.strip () [13], 32, item.strip () [16:]) for the items] outfile.write in infile (" \ n ".join (production)) outfile.close () return Outfile% to call **************************************** Main code function ******* Import file for OS, Add32 folder = 'E: / MLS_HFT / test / Stuttgart_2009_pointclouds /' os.listdir file name (folder): infilename = os.path.join (folder, file name) not os.path.isfile (infilename): the basis for the continuing expansion = os.path.splitext (filename) infile = open (infilename, 'come ') Outfile = open (os.path.join (folder,' {} {} _32 '.format (base, extension)),' mow ') add32.add_num (infile, outfile)   

this is a sample of the data:

  399299.855212 512682.330 5403021.950 303.471 64 1 1 2 75 399299.855212 512681.470 5403020.790 302.685 1 1 2 2 75 399299.855222 512682 , opened with 360 5403021,970 303,526 79 1 1 2 76    

  In the form of outfile ('infile.txt', 'rb') as infile, open ('outfile.txt', 'West Bengal'): outfile.writelines (line [: 15] '32' + line [ 15:] in-line infile)    

No comments:

Post a Comment