Can anyone explain to me why this is not working please?
I am trying to delete the first 52 lines of a text file, then skip deleting the next line, then deleting the next 100 lines, then skipping the next line and repeating the process until the file ends (requires about 100 loops), i.e. delete lines 0-51, 53-153, 155-255, 257-357 and so on about 100 hundred times.
All the lines that remain, which are what I need, are then written to a new file.
When I run this only the first 52 lines are deleted, and then nothing more happens... the script just stops. Is it because readlines is unable to hold all the data? There are about 10,000 lines in the text file!! I am VERY new to python and don't have any clue how else to do this really..
#!/usr/bin/env python # read the data file in as a list fin = open("/Users/stuartmuller/Sort/PhD/Analytical testing/Benchmark10/10a1_1/BM10a1_1/LCONR1_OUT.DAT", "r" ) lines_list = fin.readlines() fin.close() begin = 0 end = 51 count = 0 while (count < 101): del lines_list[begin:end] begin = end + 2 end = end + 100 count=count+1 # Write the updated list of lines to a new file fout = open("/Users/stuartmuller/Sort/PhD/Analytical testing/Benchmark10/10a1_1/BM10a1_1/LCONR1_BTC.DAT", "w") fout.writelines(lines_list) fout.close()