用Python实现了小说自动翻页和手动翻页两种功能,很简单,学会逻辑循环和文件操作就可以尝试自行尝试了
import time
def read_book(path,line=3,auto=False):
with open(path,mode='r') as f:
f.seek(0,2)
end=f.tell() #读取文章最末尾的光标位置
f.seek(0)
if auto==True:
while True:
for i in range(line):
print(f.readline(),end='')
now=f.tell()
if now==end:
print('已读完')
break
else:
time.sleep(3)
else:
while True:
now1=f.tell()
if now1==end:
print('已读完')
break
else:
num1=input('输入n翻下一页:')
if num1=='n':
for g in range(line):
print(f.readline(), end='')
else:
print('输入错误,请重新输入')
read_book(r'D:\pycharm\day11\a.txt')
OK~