我有下面的代码,可能会重复。也就是说,我需要在代码的不同部分搜索整个日志文件,以查看其中是否存在两种特定的模式。我不能总是在代码开始时立即搜索模式。你知道吗
但基本上,下面是我所拥有的,我正在寻找优化它的方法。假设正在读取的日志文件的大小非常大。你知道吗
textfile = open(logfile, 'r')
filetext = textfile.read()
textfile.close()
matchesBegin = re.search(BeginSearchDVar, filetext)
matchesEnd = re.search(EndinSearchDVar, filetext)
if matchesBegin is not None and matchesEnd is not None:
LRangeA = SeeIfExactRangeIsFound()
PatternCount = len(LRangeA)
LRange = '\n'.join(LRangeA)
我知道这可以优化与选项,但我不知道如何去做。你知道吗
如果您正在寻找优化,请使用^{} 。你知道吗
如果文件确实很大,您可以更改第二个参数(要映射的字节大小)以更好地满足您的需要。你知道吗
相关问题 更多 >
编程相关推荐