Jun-18-2021, 11:51 AM
Hey,
I'm struggling with a simple code. I want to extract certain lines from data files. The data files have up to a 100 times datasets after each other, so basically I want to read the same lines from each dataset. To simplify, the file that I want to read looks like this:
For reading the first dataset, this code of course works:
I'm struggling with a simple code. I want to extract certain lines from data files. The data files have up to a 100 times datasets after each other, so basically I want to read the same lines from each dataset. To simplify, the file that I want to read looks like this:
############################################## Data set 1 Value1 Value2 ################################################### Data set 2 Value1 Value2 ###################################################and so on for up to 100 datasets, and I wish to get Value1 and Value2 extracted for all of them.
For reading the first dataset, this code of course works:
file = open('filename') all_lines = file.readlines() print(all_lines[35]) print(all_lines[36]) print(all_lines[37]) print(all_lines[38]) print(all_lines[39]) print(all_lines[44]) print(all_lines[45])I tried adding a n = number of lines command but ended up printing the specific line n times instead of separate values. I'm not sure how I could get the code to pick all those certain lines that I need and print all without having to separate the number of each line I want to print - for a large amount of datasets that seems pointless. I appreciate any help!