短代码:分页读取文件中的内容
def func():
'''
主函数
:return:
'''
num = int(input("请输入要浏览的页码:"))#大于0切合法
star_info = (num-1)*10
end_info = num * 10
with open("shops",'r',encoding = 'utf-8') as f:
a = f.readline()
lis = []
count = 0
for line in f:
count += 1
if count >= star_info:
lis.append(line)
if count >= end_info:
break
print("第%s页的内容为"%(num),lis)
func()
总结:
- 在进行分页时
- star_info 及 end_info 在起始信息以及终止信息的应用