I have a file with a bunch of information with this following format:
<name>New York Jets</name>
I am trying to get each line of the file into it's own string. For example, I want this line to say "This is the roster for the New York Jets." I have this so far, but it has "This is the roster for the" for every single line. I think I have to use-
inputString.split('
')
But I'm not sure where to put it in at. This is what I have so far.
def summarizeData(filename):
with open(filename,"r") as fo:
for rec in fo:
name=rec.split('>')[1].split('<')[0]
print("Here is the roster for the %s." % (name))
and I call summarizeData("NewYorkJets.txt"). So basically I am trying to split each line from the file to get it in it's own string
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…