num=0
with open('english.txt','r')as f:
    while True:
        a=f.readline()          #对f进行按行读取
        if not a:               #循环到后面如果找不到行就结束
            break
        num+=1
        print(num,a,end='')

输出结果:

 

更多推荐

python如何读取文件并且添加行号?