中间有的行前面没有Thread Name:1.1的标识
时间: 2024-03-20 12:43:26 浏览: 67
如果你需要获取从"Thread Name:1.1 Started"到"Thread Name:1.2 Completed"之间的所有行,包括没有标识的行,你可以使用以下代码:
```python
with open("log.txt", "r") as f:
started = False
for line in f:
if "Thread Name:1.1 Started" in line:
started = True
print(line.strip())
elif "Thread Name:1.2 Completed" in line:
print(line.strip())
break
elif started:
print(line.strip())
```
这将输出:
```
Thread Name:1.1 Started
Thread Name:1.0 Running
Thread Name:1.1 Running
Thread Name:1.1 Completed
Thread Name:1.2 Started
Thread Name:1.2 Running
Thread Name:1.2 Completed
```
注意,这种方法假定"Thread Name:1.1 Started"和"Thread Name:1.2 Completed"是唯一的标识符。如果有其他行包含相同的文本,代码可能会输出不正确的行。
阅读全文