Extract Values between two strings in a text file using python

后端 未结 7 1385
闹比i
闹比i 2020-11-29 08:27

Lets say I have a Text file with the below content

fdsjhgjhg
fdshkjhk
Start
Good Morning
Hello World
End
dashjkhjk
dsfjkhk

Now I need to wr

相关标签:
7条回答
  • 2020-11-29 09:13

    I would handle it like this :

    inFile = open("data.txt")
    outFile = open("result.txt", "w")
    
    data = inFile.readlines()
    
    outFile.write("".join(data[data.index('Start\n')+1:data.index('End\n')]))
    inFile.close()
    outFile.close()
    
    0 讨论(0)
提交回复
热议问题