小编Rak*_*thi的帖子

提高搜索循环python的效率

我编写了一个代码来读取文件,查找一行是否包含该单词table_begin,然后计算直到带有单词的行的行数table_end.

这是我的代码 -

for line in read_file:
    if "table_begin" in line:
        k=read_file.index(line)
    if 'table_end' in line:
        k1=read_file.index(line)
        break

count=k1-k
if count<10:
    q.write(file)
Run Code Online (Sandbox Code Playgroud)

我必须在~15K文件上运行它,因为它有点慢(〜1个文件/秒),我想知道我是否做了一些效率低下的事情.我无法找到自己,所以任何帮助都会很棒!

python performance loops

1
推荐指数
1
解决办法
107
查看次数

标签 统计

loops ×1

performance ×1

python ×1