在python中查找并检查行

2024-05-15 05:46:17 发布

您现在位置: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。 这是我的台词: 字30:0x01312e58


Tags: intxtforreturnifdefcheckas
2条回答

除了Christopher Peisert发布的链接外,还可以查看这个链接,Find keywords in a text file

另外,请阅读关于如何提问的指南,并实际提问。谢谢

我希望你的期望是这样的


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

相关问题 更多 >

    热门问题