如何打印文本文件,直到它与字符串匹配。考虑以下文本文件:00:d7:8f:0a:86:5c ST0123-AP22 Joined Flexconnect Manual No00:d7:8f:1e:d6:18 ST0123-AP14 Joined Flexconnect Manual No00:d7:8f:1e:dd:50 ST0123-AP03 Joined Flexconnect Manual NoEfficient AP Image Upgrade ..... EnabledGroup Radius/Local Auth Parameters : Radius Retransmit Count......................... 3 (default) Active Radius Timeout........................... 5 (default)Group Radius AP Settings:AP RADIUS server............ DisabledEAP-FAST Auth............... DisabledLEAP Auth................... DisabledEAP-TLS Auth................ DisabledEAP-TLS CERT Download....... DisabledPEAP Auth................... Disabled我想打印直到字符串“Efficient AP Image Upgrade ..... Enabled”的行:问题是行数因每个输出而异。我也尝试过 readlines 和 ttried for loop 但无法实现目标。
1 回答
九州编程
TA贡献1785条经验 获得超4个赞
这应该工作:
with open('your_file.txt') as file:
for line in file:
if line == 'Efficient AP Image Upgrade ..... Enabled\n':
break
print(line)
添加回答
举报
0/150
提交
取消