推荐学习书目
› 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
cc7756789
V2EX  ›  Python

如何覆盖上一次的打印结果

  •  
  •   cc7756789 · May 29, 2015 · 6436 views
    This topic created in 4141 days ago, the information mentioned may be changed or developed.
    就比如像下面这种循环结果,倒计时
    ``` python
    count = 0
    b = 60
    while (count < b):
    count += 1
    n = b - count
    print n
    time.sleep(1)
    ```
    如果覆盖上一次print的结果
    7 replies  •  2015-05-31 09:29:22 +08:00
    ipconfiger
        1
    ipconfiger  
       May 29, 2015
    print “\b\b\b\b”
    jedyu
        2
    jedyu  
       May 29, 2015
    \b 回到行首
    LeoQ
        3
    LeoQ  
       May 29, 2015 via Android
    clear能用么
    Sylv
        4
    Sylv  
       May 29, 2015
    import sys
    import time

    print '1',
    sys.stdout.flush() # 输出缓存
    time.sleep(1)
    print '\r', # 回车符回到行首
    print '2',
    lzachilles
        5
    lzachilles  
       May 29, 2015
    cnt = 1
    while True:
    cnt += 1
    print cnt,
    print '\r',
    n37r06u3
        6
    n37r06u3  
       May 29, 2015
    回车符 就是换行 想想打字机
    cc7756789
        7
    cc7756789  
    OP
       May 31, 2015
    搞定但是先问题无法解决,就是倒计时输出会在最左边输出,如何把它禁锢在指定的区域呢?
    ```
    def interface_show(**kwargs):
    print ' '*5, kwargs['title'], kwargs['artist'], kwargs['rate'], time_remain(kwargs['minutes'])

    def time_remain(mins):
    count = 0
    while (count < mins):
    count += 1
    n = mins - count
    time.sleep(1)
    sys.stdout.write("%d \r" % n,)
    sys.stdout.flush()
    if not n:
    return 'completed'
    ```


    最后输出这样的信息,最右边的是总时长,最左边的是倒计时效果。
    108 <旅立ち(「はるかな旅」ストリングス·ヴァージョン)> 吉田潔 ★★★★ 205
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   3262 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 41ms · UTC 04:23 · PVG 12:23 · LAX 21:23 · JFK 00:23
    ♥ Do have faith in what you're doing.