Read Up Until a Point Python
python, python-3.3, readlines, text
Solution
You're pretty close, as you are. You just need to modify your list slice to chop off the last two lines in the file along with the first two. `readlines` will naturally return a list where each item is one line from the file. However, it will also have the 'newline' character at the end of each string, so you may need to filter that out.
with open("myfile.txt") as myfile:
# Get only numbers
read = myfile.readlines()[2:-2]
# Remove newlines
read = [number.strip() for number in read]
print read
Problem
I have a text file full of data that starts with ``` #Name #main ``` then it's followed by lots of numbers and then the file ends with ``` #extra !side ``` So here's a small snippet ``` #Name #main 60258960 33031674 72302403 #extra !side ``` I want to read only the numbers. But here's the kick, I want them to each be their own individual string. So I know how to read starting after the headers with ``` read=f.readlines()[3:] ``` But I'm stumped on everything else. Any suggestions?