質問編集履歴
2
スクリプトの一部変更
test
CHANGED
File without changes
|
test
CHANGED
@@ -56,15 +56,15 @@
|
|
56
56
|
|
57
57
|
for p in range(1,lines-5):
|
58
58
|
|
59
|
-
target_line1 = linecache.getline("
|
59
|
+
target_line1 = linecache.getline("data.dat",p)
|
60
60
|
|
61
|
-
target_line2 = linecache.getline("
|
61
|
+
target_line2 = linecache.getline("data.dat",p+1)
|
62
62
|
|
63
|
-
target_line3 = linecache.getline("
|
63
|
+
target_line3 = linecache.getline("data.dat",p+2)
|
64
64
|
|
65
|
-
target_line4 = linecache.getline("
|
65
|
+
target_line4 = linecache.getline("data.dat",p+3)
|
66
66
|
|
67
|
-
target_line5 = linecache.getline("
|
67
|
+
target_line5 = linecache.getline("data.dat",p+4)
|
68
68
|
|
69
69
|
|
70
70
|
|
1
不足していた情報の説明
test
CHANGED
File without changes
|
test
CHANGED
@@ -39,3 +39,39 @@
|
|
39
39
|
…
|
40
40
|
|
41
41
|
のように一文字ずつ改行されているものとします。想定としてはdata.datは5万行程度のデータなので何かしらの工夫が必要だと思うのですが…。
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
追記1
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
たとえば、一つ目のプロセスに関しては、
|
50
|
+
|
51
|
+
```python
|
52
|
+
|
53
|
+
lines = len(open('data.dat').readlines())
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
for p in range(1,lines-5):
|
58
|
+
|
59
|
+
target_line1 = linecache.getline("log2.dat",p)
|
60
|
+
|
61
|
+
target_line2 = linecache.getline("log2.dat",p+1)
|
62
|
+
|
63
|
+
target_line3 = linecache.getline("log2.dat",p+2)
|
64
|
+
|
65
|
+
target_line4 = linecache.getline("log2.dat",p+3)
|
66
|
+
|
67
|
+
target_line5 = linecache.getline("log2.dat",p+4)
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
if target_line1 == 1 and target_line2 == 1 and target_line3 == 0 and target_line4 == 1 and target_line5 == 1:
|
72
|
+
|
73
|
+
#p+3行目を1に書き換える
|
74
|
+
|
75
|
+
```
|
76
|
+
|
77
|
+
とすればよいのでしょうが、data.datの特定の行を書き換える方法がわかりません。
|