首页 > 解决方案 > 在python中查找并检查行

问题描述

def check():
    with open('cefuse.txt') as f:
        datafile = f.readlines()
    for line in datafile:
        if line starts with 'Word 30' and contains only 0
            return True
    return False 

我想检查 .txt 文件中的一行。如果它仅包含 0,则 retcode 将 1 否则为 0。这是我的行:Word 30 : 0x01312e58

标签: python

解决方案


我希望你期待这样。


def check():
    with open('cefuse.txt') as f:
        datafile = f.readlines()
    for line in datafile:
        if line startswith('Word 30') and '0' in line:
            return True
    return False

推荐阅读