python2 注释

def get_file_last_lines(file_name, start_line_pos, nums=10):
  """
  获取文件指定位置开始后的行数
  :param file_name: str, 文件名绝对路径
  :param start_line_pos: int, 从第几行开始取
  :param nums: int, 需要返回的文件行数
  :return: []
  """
  result = []
  with open(file_name, "r") as f:
    index = 0
    while True:
      temp = f.readline()
      if not temp or 0>=nums:
        break
      index += 1
      if index >= start_line_pos:
        result.append(temp)
        nums -= 1
  return result


 

 

 

 posted on 2019-12-12 20:33  墨语i  阅读(416)  评论(0)    收藏  举报