Hello, I have a python script that deletes a line of a text file when the number in the second column is greater than or equal to 5.
So my input file is three columns:
1 3 aaa
2 3 aaa
3 6 aaaaaa
4 2 aaa
def filter(in_file, output):
F_OUT= open(output, 'w')
pos = []
rd = []
gc = []
for line in in_file:
number = line.split()
pos.append(number[0])
rd.append(number[1])
gc.append(number[2])
for i in number[1]:
if int(i) >= 5:
del number[0]
del number[0]
del number[0]
F_OUT.write(str(number[0]).ljust(10) + str(number[1].ljust(10)) + str(number[2]))
F_OUT.write('\n')
filter(in_file, results)
I want my output file to contain all the same data and setup, except for the deleted line like below.
1 3 aaa
2 3 aaa
4 2 aaa
But I get an error message
Traceback (most recent call last):
F_OUT.write(str(number[0]).ljust(10) + str(number[1].ljust(10)) + str(number[2]))
IndexError: list index out of range
Does anyone know how I can rectify the problem?
Thanks.