📜  在 python 代码示例中逐行读取文件

📅  最后修改于: 2022-03-11 14:45:15.546000             🧑  作者: Mango

代码示例1
filepath = 'Iliad.txt'
with open(filepath) as fp:
   line = fp.readline()
   cnt = 1
   while line:
       print("Line {}: {}".format(cnt, line.strip()))
       line = fp.readline()
       cnt += 1