推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
PanameraM
V2EX  ›  Python

一道 python 题,大家给帮帮忙, thx!

  •  
  •   PanameraM · Oct 28, 2016 · 2374 views
    This topic created in 3684 days ago, the information mentioned may be changed or developed.

    题目如下: 写一个逐页显示文本文件的程序. 提示输入一个文件名, 每次显示文本 文件的 25 行, 暂停并向用户提示"按任意键继续.", 按键后继续执行

    6 replies  •  2016-10-29 09:12:31 +08:00
    eyp82
    eyp82
    Oct 28, 2016❤️1
    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)
    eyp82
    eyp82
    Oct 28, 2016
    2
    缩进都被吃掉了....
    PanameraM
    PanameraM
    OP
    Oct 28, 2016
    3
    @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)
    PanameraM
    PanameraM
    OP
    Oct 28, 2016
    4
    @eyp82 ...我的也被吃掉了。。
    btjoker
    btjoker
    Oct 28, 2016
    5
    @Tianny 试试全角空格
    yexiaoxing
    yexiaoxing
    Oct 29, 2016 via Android
    6
    试试 gist …
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1046 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 23:43 · PVG 07:43 · LAX 15:43 · JFK 18:43
    ♥ Do have faith in what you're doing.