python分页查询数据处理方法

def view_per_data(page_num, per_page_data):
    '''
    获取指定页码的数据
    :param page_num: 页码
    :param per_page_data: 每页数据
    :return:
    '''
    page_num = int(page_num)
    per_page_data = int(per_page_data)
    view_data = []
    view_data_count = 0
    file_data = open('test.txt',mode='r',encoding='utf-8')
    stat_index = (page_num - 1) * per_page_data
    end_index = page_num * per_page_data
    for line in file_data:
        if stat_index <= view_data_count < end_index:
            view_data.append(line.strip())
        if view_data_count >= end_index:
            break
        view_data_count += 1

    return view_data
上一篇:B. Double Matrix--- 思维题--Codeforces Round #557 (Div. 2)


下一篇:B站黑马c++学习笔记 —— 通讯录案例