This is the question continous from my previous question. Thank to many people, I could modify my code as below.
import csv
with open("SURFACE2", "rb") as infile, open("output.txt", "wb") as outfile:
reader = csv.reader(infile, delimiter=" ")
writer = csv.writer(outfile, delimiter=" ")
for row in reader:
row[18] = "999"
writer.writerow(row)
I just change delimiter from "\t" to " ". Whiel with previous delimiter, the code only worked upto row[0], with " " the code can work until row[18].
15.20000 120.60000 98327 get data information here. SURFACE DATA FROM ??????????? SOURCE FM-12 SYNOP 155.00000 1 0 0 0 0 T F F -888888 -888888 20020601030000 100820.00000
From the data line above, row[18] is just in the middle between 15.20000 and 120.60000.
I am not sure what happens in between these two values. Maybe delimiter changes? However visually I can't notice any difference. Is there any way which I can know the delimiter changed and if so, do you have any idea to handle multiple delimiter for one code?
Any idea or help would be really appreciated.
Thank you, Isaac
The results from repr(next(infile)):
' 15.20000 120.60000 98327 get data information here. SURFACE DATA FROM ??????????? SOURCE FM-12 SYNOP 155.00000 1 0 0 0 0 T F F -888888 -888888 20020601030000 100820.00000 0-888888.00000 0-888888.00000 0-888888.00000 0-888888.00000 0-888888.00000 0-888888.00000 0-888888.00000 0-888888.00000 0-888888.00000 0-888888.00000 0-888888.00000 0-888888.00000 0\n'
' 99070.00000 0 155.00000 0 303.20001 0 297.79999 0 3.00000 0 140.00000 0-888888.00000 0-888888.00000 0-888888.00000 0-888888.00000 0\n'
'-777777.00000 0-777777.00000 0 1.00000 0-888888.00000 0-888888.00000 0-888888.00000 0-888888.00000 0-888888.00000 0-888888.00000 0-888888.00000 0\n'
' 1 0 0\n'
' 55.10000 -3.60000 03154 get data information here. SURFACE DATA FROM ??????????? SOURCE FM-12 SYNOP 16.00000 1 0 0 0 0 T F F -888888 -888888 20020601030000-888888.00000 0-888888.00000 0-888888.00000 0-888888.00000 0-888888.00000 0-888888.00000 0-888888.00000 0-888888.00000 0-888888.00000 0-888888.00000 0-888888.00000 0-888888.00000 0-888888.00000 0\n'
'-888888.00000 0 16.00000 0 281.20001 0 279.89999 0 0.00000 0 0.00000 0-888888.00000 0-888888.00000 0-888888.00000 0-888888.00000 0\n'
'-777777.00000 0-777777.00000 0 1.00000 0-888888.00000 0-888888.00000 0-888888.00000 0-888888.00000 0-888888.00000 0-888888.00000 0-888888.00000 0\n'
' 1 0 0\n'
As you can see actually four first lines should be one line. For some reason, full line seems divided into 4 parts. Do you have any idea? Thank you, Isaac