python读取文件固定行 Posted on 2019-08-26 | In python Words count in article: 52 | Reading time ≈ 1 内置库 linecache 123456789>>> 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()...>>> get_line_context(file_path, line_number)'This is line 5.'