Вы можете прочитать файл в виде списка строк (назовите его fileList), где каждая строка представляет собой отдельную строку:
f = open('filename')
fileList = f.readlines()
Затем удалите часть заголовка вашего файла с помощью
fileList.pop(0)
fileList.pop(0)
Затем сделайте
outFileContents = {} # This will be a dict, where number -> content of test_number.dat
for outFileName in range(1,41): #outFileName will be the number going after the _ in your filename
outFileContents[outFileName] = []
for n in range(40): # Counting through the time blocks
currentRowIndex = (42 * n) + outFileName # 42 to account for the Time = and blank row
outFileContents[outFileName].append(fileList[currentRowIndex])
Наконец, вы можете перебрать outFileContents и записать содержимое каждого значения в отдельные файлы.