回答編集履歴

1

コード修正

2018/11/20 09:20

投稿

can110
can110

スコア38266

test CHANGED
@@ -8,60 +8,78 @@
8
8
 
9
9
  ```Python
10
10
 
11
+ fin = open('inp.csv','r')
12
+
11
- with open('out.csv','w') as fw: # 合格ファイル名の一覧を出力
13
+ fok = open('ok.csv','w') # 合格
14
+
15
+ fng = open('ng.csv','w') # 不合格
12
16
 
13
17
 
14
18
 
15
- # 現在判定対象のファイル名、条件'1'ありか、詳細`succeed`ありか
19
+ # 現在判定対象のファイル名、条件'1'ありか、詳細`succeed`ありか
16
20
 
17
- file,is_one,is_succeed = '',False,False
21
+ file,is_one,is_succeed = '',False,False
18
22
 
19
23
 
20
24
 
21
- with open('inp.csv','r') as fr:
25
+ line = fin.readline().strip()
22
26
 
23
- line = fr.readline().strip()
27
+ while line:
24
28
 
25
- while line:
29
+ f,no,desc = line.split(',') # ファイル名,条件,詳細
26
30
 
27
- f,no,desc = line.split(',') # ファイル名,条件,詳細
28
-
29
- line = fr.readline().strip()
31
+ line = fin.readline().strip()
30
32
 
31
33
 
32
34
 
33
- # ファイル名の切り替わり
35
+ # ファイル名の切り替わり
34
36
 
35
- # 現在判定中ファイル名の処理
37
+ # 現在判定中ファイル名の処理
36
38
 
37
- if file != f:
39
+ if file != f:
38
40
 
39
- #print(file,is_one,is_succeed)
41
+ if len(file) > 0:
40
42
 
41
- if len(file) > 0 and (not is_one) and is_succeed:
43
+ if (not is_one) and is_succeed:
42
44
 
43
- fw.write(file+'\n')
45
+ fok.write(file+'\n')
44
46
 
47
+ else:
48
+
49
+ fng.write(file+'\n')
50
+
45
- file,is_one,is_succeed = f,False,False
51
+ file,is_one,is_succeed = f,False,False
46
52
 
47
53
 
48
54
 
49
- if no == '1':
55
+ if no == '1':
50
56
 
51
- is_one = True
57
+ is_one = True
52
58
 
53
- if desc == 'succeed':
59
+ if desc == 'succeed':
54
60
 
55
- is_succeed = True
61
+ is_succeed = True
62
+
63
+ fin.close()
56
64
 
57
65
 
58
66
 
59
- # 最後の行
67
+ # 最後の行
60
68
 
61
- #print(file,is_one,is_succeed)
69
+ if len(file) > 0:
62
70
 
63
- if len(file) > 0 and (not is_one) and is_succeed:
71
+ if (not is_one) and is_succeed:
64
72
 
65
- fw.write(file+'\n')
73
+ fok.write(file+'\n')
74
+
75
+ else:
76
+
77
+ fng.write(file+'\n')
78
+
79
+
80
+
81
+ fok.close()
82
+
83
+ fng.close()
66
84
 
67
85
  ```