I have tried numerous ways to parse a file and strip the array down to only the text inside the "". However, I seem to be unable to figure out the correct syntax for it. I assumed the issue might have been from trying to access an element which didn't exist (because no " was in the file line), but that wasn't the issue.
The code only works if I explicitly say
However, that's not what I want. I want it to loop by itself.
Text.txt:
The code only works if I explicitly say
sa_data[1] = sa_data[1].split('"')[1]
However, that's not what I want. I want it to loop by itself.
Text.txt:
<tag1> <tag2 name = "tag 2"> <tag3 name="korea"/> <tag4 name="china"/> <tag5 name="japan"/> </tag2> </tag1>Code:
sa_data = [] with open('Text.txt') as fin: s_Line = fin.readline() for s_Line in fin: sa_data.append(s_Line) for i in sa_data: if range(sa_data[i].split('"')) is 3: sa_data[i] = sa_data[i].split('"')[1]Ideally, what I wanted is something like:
sa_data = [] with open('Text.txt') as fin: s_Line = fin.readline() for s_Line in fin: sa_data.append(s_Line.split('"')[1]