相关疑难解决方法(0)

Python:循环读取所有文本文件行

我想逐行读取大文本文件(如果找到带有"str"的行,则停止).如果到达文件结尾怎么检查?

fn = 't.log'
f = open(fn, 'r')
while not _is_eof(f): ## how to check that end is reached?
    s = f.readline()
    print s
    if "str" in s: break
Run Code Online (Sandbox Code Playgroud)

python file

49
推荐指数
3
解决办法
18万
查看次数

标签 统计

file ×1

python ×1