I am trying to follow a answer given here:
How to only read lines in a text file after a certain string using python?
in reading only the line after a certain phrase in which I went the boolean route, or the second answer.
I need to get just the numbers between a two opening and closing section from a file
<type>
1
2
3
<type>
However when I used this code:
found_type = False
t_ype = []
with open('test.xml', 'r') as f:
for line in f:
if '<type>' in line:
found_type = True
if found_type:
if '</type>' in line:
found_type = False
else:
t_line = str(line).rstrip('\n')
t_ype.append(t_line)
I can't get skip the first line and get :
'<type>', '1','2','3'
Where I just want
'1','2','3'
while ending the appending to the list when I hit as I don't need that in my list
I'm not sure what I'm doing wrong and can't ask on the page because my rep isn't high enough.