I have a program which opens a file, searches for a string ("Performance Summary"), misses 3 lines then copies the following lines until there are no more.
# Extracts data from a files and saves it in a summary file with open("file1.txt") as file: for line in file: if 'Performance Summary' in line: # Starting point data_lines =  for i in range(3): next(file) # Advance 3 lines data = next(file).strip() # read the 4th line, remove whilte spaces while data: # while data isn't an empty line data_lines.append(data) # store in list data = next(file).strip() # keep reading... break # stop checking lines with open("summary.txt", "w") as out_file: out_file.write("".join(data_lines))
Each line which is being copied is something like this:
1000.0 3.86 36.90 7.74 273.51 63.1 1.000 1.002 No ( 10)
Where I need to copy the first and third element to generate an output something like:
I tried using:
data.split() first = data.pop(0) third = data.pop(2)
But, I got "AttributeError: 'str' object has no attribute 'pop'" which I'm guessing is because I only have a line of text and not a list. I can't find any conversion which will work.
Hope you can help,
Edited by Kitson: n/a