回答編集履歴
1
追記
test
CHANGED
@@ -43,3 +43,45 @@
|
|
43
43
|
# out01.txt,out02.txt...が生成される
|
44
44
|
|
45
45
|
```
|
46
|
+
|
47
|
+
あるいは各データ群をリストに格納すれば、ファイル出力することなく、より簡潔に処理できます。
|
48
|
+
|
49
|
+
```Python
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
# 1データ群の処理
|
54
|
+
|
55
|
+
def func(lst):
|
56
|
+
|
57
|
+
print(lst[1:]) # 見出し行を除いて出力
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
lst = []
|
62
|
+
|
63
|
+
with open('inp.txt') as f:
|
64
|
+
|
65
|
+
for line in f:
|
66
|
+
|
67
|
+
line = line.rstrip()
|
68
|
+
|
69
|
+
if len(line.split()) == 2: # 出力する行
|
70
|
+
|
71
|
+
lst.append(line)
|
72
|
+
|
73
|
+
else: # 出力行の切り替わり
|
74
|
+
|
75
|
+
if len(lst) > 0:
|
76
|
+
|
77
|
+
func(lst)
|
78
|
+
|
79
|
+
lst = []
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
if len(lst) > 0:
|
84
|
+
|
85
|
+
func(lst)
|
86
|
+
|
87
|
+
```
|