回答編集履歴
2
追記
test
CHANGED
@@ -69,3 +69,43 @@
|
|
69
69
|
print(emb)
|
70
70
|
|
71
71
|
```
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
コメントを受けて
|
76
|
+
|
77
|
+
---
|
78
|
+
|
79
|
+
> もし"Query="が複数ある場合でそのすべてを同じように抽出するときはどう書けばいいでしょうか。
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
```Python
|
84
|
+
|
85
|
+
with open(r'blastn.txt') as fin:
|
86
|
+
|
87
|
+
while True:
|
88
|
+
|
89
|
+
for line in fin:
|
90
|
+
|
91
|
+
if 'Query=' in line: # line.startswith('Query=') の方が良い
|
92
|
+
|
93
|
+
print(line[:-1])
|
94
|
+
|
95
|
+
break
|
96
|
+
|
97
|
+
else:
|
98
|
+
|
99
|
+
break
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
for _ in range(5):
|
104
|
+
|
105
|
+
next(fin)
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
print(next(fin)[:-1])
|
110
|
+
|
111
|
+
```
|
1
追記
test
CHANGED
@@ -23,3 +23,49 @@
|
|
23
23
|
print(next(fin)[:-1])
|
24
24
|
|
25
25
|
```
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
---
|
30
|
+
|
31
|
+
ちょっと捻っても書けます。参考までに。
|
32
|
+
|
33
|
+
```Python
|
34
|
+
|
35
|
+
import collections
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
queue = collections.deque(maxlen=7)
|
40
|
+
|
41
|
+
for _ in range(queue.maxlen):
|
42
|
+
|
43
|
+
queue.append('')
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
with open(r'blastn.txt') as fin:
|
48
|
+
|
49
|
+
for line in map(str.rstrip, fin):
|
50
|
+
|
51
|
+
queue.append(line)
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
if queue[0].startswith('Query='):
|
56
|
+
|
57
|
+
break
|
58
|
+
|
59
|
+
else:
|
60
|
+
|
61
|
+
raise ValueError
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
q, *_, emb = queue
|
66
|
+
|
67
|
+
print(q)
|
68
|
+
|
69
|
+
print(emb)
|
70
|
+
|
71
|
+
```
|