Extract Paragraph with specific words between two similar titiles

前端 未结 2 1673
再見小時候
再見小時候 2021-01-23 10:10

my text file contains, paragraphs something like this.

summary

A result oriented and dedicated professional with three years’ experience in Software Development         


        
2条回答
  •  我在风中等你
    2021-01-23 10:25

    To extract all summary sections that contain the words you are interested in:

    split_on = 'summary\n\n'
    must_contain = ['Project', 'Team Size']
    
    with open('9.txt') as f_input, open('d.txt', 'w') as f_output:
        for part in f_input.read().split(split_on):
            if all(text in part for text in must_contain):
                f_output.write(split_on + part)
    

提交回复
热议问题