题目如下: 写一个逐页显示文本文件的程序. 提示输入一个文件名, 每次显示文本 文件的 25 行, 暂停并向用户提示"按任意键继续.", 按键后继续执行
1
eyp82 2016-10-28 07:20:51 +08:00 1
随手撸了一个, 代码有点烂, 哪里有 bug 还请各位不吝指出:
#!/usr/bin/env python3 def show_content(file, paginate): """Show the content of a file, display 'paginate' lines and ask user to press any key to continue""" with open(file) as f: for idx, line in enumerate(f, start=1): print(line, end='') if not idx % paginate: print('Press any key to continue') _ = input() if __name__ == '__main__': show_content('test.out', 25) |
2
eyp82 2016-10-28 07:22:44 +08:00
缩进都被吃掉了....
|
3
Tianny OP @eyp82 thx !我再把缩进的给补回来
#!/usr/bin/env python3 def show_content(file, paginate): """show the content of a file,display paginate lines and ask user to press any key to continue""" with open(file) as f: for idx, line in enumerate(f, start=1): print (line,end='') if not idx % paginate: print ('Press any key to continue') _ = input() if __name__ == '__main__': show_content('/home/tiantian/.vimrc', 25) |
6
yexiaoxing 2016-10-29 09:12:31 +08:00 via Android
试试 gist …
|