How to use split function for file in python?

后端 未结 3 1626
独厮守ぢ
独厮守ぢ 2021-01-28 05:53

I have a file with a bunch of information. For example, all of the lines follow the same pattern as this:

     Nebraska
         


        
3条回答
  •  鱼传尺愫
    2021-01-28 06:31

    You could use a regular expression:

    import re
    regexp = re.compile('(.*?)<\/school>')
    
    with open('Pro.txt') as fo:
        for rec in fo:
            match = regexp.match(rec)
            if match: 
                text = match.groups()[0]
                print(text)
    

提交回复
热议问题