📜  编写一个 Python 程序来读取文件的最后 n 行 - Python 代码示例

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

代码示例1
def read_lastnlines(fname,n):
    with open('file1.txt') as f:
        for line in (f.readlines() [-n:]):
            print(line)

read_lastnlines('file1.txt',3)