且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

提取文本文件中两个字符串之间的值

更新时间:2023-02-12 18:38:58

大问题!这是一个桶问题,每个起点都需要一个终点.

Great problem! This is a bucket problem where each start needs an end.

之所以得到结果,是因为有两个连续的开始".

The reason why you got the result is because there are two consecutive 'Start'.

***将信息存储到某个地方,直到触发"End"为止.

It's best to store the information somewhere until 'End' is triggered.

infile = open('scores.txt','r')
outfile= open('testt.txt','w')
copy = False
for line in infile:

    if line.strip() == "Start":
        bucket = []
        copy = True

    elif line.strip() == "End":
        for strings in bucket:
            outfile.write( strings + '\n')
        copy = False

    elif copy:
        bucket.append(line.strip())