Python使用字符串检查文件内容

2024-05-14 22:10:59 发布

您现在位置:Python中文网/ 问答频道 /正文

你好!我有以下脚本:

import os
import stat

curDir = os.getcwd()

autorun_signature = [ "[Autorun]",
                      "Open=regsvr.exe",
                      "Shellexecute=regsvr.exe",
                      "Shell\Open\command=regsvr.exe",
                      "Shell=Open" ]

content = []

def read_signature(file_path):
    try:
        with open(file_path) as data:
            for i in range(0,5):
                content.append(data.readline())
    except IOError as err:
        print("File Error: "+   str(err))

read_signature(os.getcwd()+'/'+'autorun.inf')

if(content==autorun_signature):
    print("Equal content")
else:
    print("Not equal")

它打印不相等,然后我尝试了这个方法:

^{pr2}$

它也印不相等! 我想存储自动运行.inf文件在脚本和每次我发现这样的文件我想检查它的内容,如果它是不是,我做不到,谁能帮我? 内容自动运行公司名称:

[Autorun]
Open=regsvr.exe
Shellexecute=regsvr.exe
Shell\Open\command=regsvr.exe
Shell=Open

Tags: import脚本osopencontentshellexecommand

热门问题