質問編集履歴
1
書式の改善
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,93 +1,5 @@
|
|
1
|
-
|
1
|
+
pythonで複数のテキストファイルを読み込みたい
|
2
|
-
|
3
|
-
ご教示のほどよろしくおねがいします。
|
4
2
|
|
5
3
|
|
6
4
|
|
7
|
-
list.log
|
8
|
-
|
9
|
-
10250.log
|
10
|
-
|
11
|
-
10243.log
|
12
|
-
|
13
|
-
10525.log
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
#list.logの記載のファイル名に対して、以下の処理を1度ずつ実行したい。
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
#行を取得
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
with open(path, "r", encoding="utf-8") as f:
|
32
|
-
|
33
|
-
lines = f.readlines()
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
#改行を削除
|
42
|
-
|
43
|
-
lines_strip = [line.strip() for line in lines]
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
#条件を満たす行のみ取得
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
Value1 = [line for line in lines_strip if 'error' in line]
|
54
|
-
|
55
|
-
Value2 = [line for line in lines_strip if 'ERROR' in line]
|
56
|
-
|
57
|
-
Value3 = [line for line in lines_strip if 'WARN' in line]
|
58
|
-
|
59
|
-
Value4 = [line for line in lines_strip if 'Warn' in line]
|
60
|
-
|
61
|
-
Value5 = [line for line in lines_strip if 'Error' in line]
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
5
|
+
もし何か方法があれば教えてください。
|
68
|
-
|
69
|
-
print(Value1[0])
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
for line in Value2:
|
74
|
-
|
75
|
-
print(Value2[0])
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
for line in Value3:
|
80
|
-
|
81
|
-
print(Value3[0])
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
for line in Value4:
|
86
|
-
|
87
|
-
print(Value4[0])
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
for line in Value5:
|
92
|
-
|
93
|
-
print(Value1[0])
|