回答編集履歴
1
追記
test
CHANGED
@@ -23,3 +23,31 @@
|
|
23
23
|
lines_after = [line for line in f if 'XXX' not in line]
|
24
24
|
|
25
25
|
```
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
おまけ
|
30
|
+
|
31
|
+
---
|
32
|
+
|
33
|
+
次のように読み出しと書き出しを同時に行うと、更にメモリ効率が良くなります。
|
34
|
+
|
35
|
+
```Python
|
36
|
+
|
37
|
+
with open(rfile) as fin, open(wfile) as fout:
|
38
|
+
|
39
|
+
for line in fin:
|
40
|
+
|
41
|
+
if 'XXX' in line:
|
42
|
+
|
43
|
+
continue
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
fout.write(line)
|
48
|
+
|
49
|
+
```
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
ここまで来るとシェルスクリプトやバッチの方がすっきりしそうなのはさておき。
|