read file into array separated by paragraph Python

后端 未结 7 908
半阙折子戏
半阙折子戏 2021-02-08 22:11

I have a text file, I want to read this text file into 3 different arrays, array1 array2 and array3. the first paragraph gets put in array1, the second paragraph gets put in arr

7条回答
  •  有刺的猬
    2021-02-08 22:35

    This code will search for lines between two points:

    rr = [] #Array for saving lines    
    for f in file_list:
        with open(f, 'rt') as fl:
            lines = fl.read()
            lines = lines[lines.find('String1'):lines.find('String2')] 
            rr.append(lines)
    

提交回复
热议问题