Read multiple block of file between start and stop flags

前端 未结 4 1177
轮回少年
轮回少年 2020-12-06 23:53

I am trying to read sections of a file into numpy arrays that have similar start and stop flags for the different sections of the file. At the moment I have found a method

4条回答
  •  一整个雨季
    2020-12-07 00:37

    You have indentation problem, your code should look like this:

    with open("myFile.txt") as f:
        array = []
        parsing = False
        for line in f:
            if line.startswith('stop flag'):
            parsing = False
            if parsing:
            #do things to the data
            if line.startswith('start flag'):
            parsing = True
    

提交回复
热议问题