回答編集履歴
2
コード修正
answer
CHANGED
@@ -25,8 +25,10 @@
|
|
25
25
|
|
26
26
|
with fin_path.open() as fin:
|
27
27
|
result = analyze_file(fin)
|
28
|
-
if not result:
|
29
|
-
continue
|
30
28
|
|
29
|
+
if not result:
|
30
|
+
continue
|
31
|
+
|
31
|
-
|
32
|
+
with fout_path.open(mode='w') as fout:
|
33
|
+
fout.writelines(result)
|
32
34
|
```
|
1
追記
answer
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
pathlibを使うとこんな感じです。
|
1
|
+
[pathlib](https://docs.python.jp/3/library/pathlib.html)を使うとこんな感じです。
|
2
2
|
```Python
|
3
3
|
from operator import itemgetter
|
4
4
|
from pathlib import Path
|
@@ -18,7 +18,7 @@
|
|
18
18
|
|
19
19
|
parent_dir = Path(r'textがあるディレクトリ')
|
20
20
|
for filename in parent_dir.glob('text*.txt'):
|
21
|
-
i = int(filename.name[4])
|
21
|
+
i = int(filename.name[4]) # 二桁以上の場合もあるならもうちょっと工夫が必要
|
22
22
|
|
23
23
|
fin_path = (parent_dir / f'text{i}.txt')
|
24
24
|
fout_path = (parent_dir / f'narabikae{i}.txt')
|