Python读取文件指定行 By admin | 2022-01-16 阅读次数: 读取指定行import linecache file_path = r'D:\work\python\test.txt' line_number = 5 def get_line_context(file_path, line_number): return linecache.getline(file_path, line_number).strip()