簡體   English   中英

python中的Linecache不緩存指定的行

[英]Linecache in python is not caching the lines specified

我正在使用linecache在出現字符串之前獲取行。 但這是行不通的。 我不明白是什么問題?

with open(fileName, 'r') as inFile:
    between = False
        for num, line in enumerate(inFile, 1):
        if st_time in line:
            between = True
        if between:
            if 'Broken pipe' in line:
                line1 = linecache.getline(fileName, num-55)
            if 'ERROR' in line1:
                print("yes")
        if en_time in line:
            between = False

你們中提到的就是這個問題。 Linecache不會存儲整行,而只會存儲指定的行。 例如line1 = linecache.getline(fileName,num-22)將僅存儲第(num -22)行。 我以為它將存儲到第(num-22)行。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM