跳至主要內容
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?

4563博客

全新的繁體中文 WordPress 網站
  • 首頁
  • Python 命令行下多行刷新(终于解决)
未分類
22 7 月 2020

Python 命令行下多行刷新(终于解决)

Python 命令行下多行刷新(终于解决)

資深大佬 : lswang 7

前言

之前看到很多软件都能在命令行下多行刷新,可在python 的默认打印中只能支持单行刷新。 网上搜了很多文章都没有解决这个问题。后来看到ANSI ESCAPE CODES`相关的概念,终于看到了曙光。 参考文档 wiki

python 代码示例

注: 在命令行下执行 python 文件才可以

# -*- coding:utf8 -*- import time,sys def progressbar():     print 'Loading...'     print "[+] start to build...."     height = 4     for i in range(0, 100):         if i > 0:             sys.stdout.write(u'u001b[1A')         time.sleep(0.1)         width = (i + 1) / 4         bar = '[' + '#' * width + ' ' * (25 - width) + ']'         sys.stdout.write(u'u001b[1000Du001b[2K' + ' | -> ' + bar + 'n')         sys.stdout.write(u'u001b[1000Du001b[2K' + ' | -> ' + bar)         sys.stdout.flush()       sys.stdout.write(u'u001b[1A')     sys.stdout.write(u'u001b[1A')     sys.stdout.write(u'u001b[1000D')     sys.stdout.write(u'u001b[J')     sys.stdout.write('[-] Finish build')     sys.stdout.flush()     print progressbar()  

大佬有話說 (13)

  • 資深大佬 : w9ay

    谢谢分享,正好需要

  • 資深大佬 : xJogger

    Python 3 运行失败。
    代码:
    https://pastebin.ubuntu.com/p/6hY5fVMPWp/
    效果图:
    https://i.loli.net/2020/07/16/IH1uJhKC2qifpxR.png

  • 資深大佬 : deorth

    妙啊

  • 資深大佬 : a719114136

    你要的是这个吧 https://www.v2ex.com/t/680258

  • 資深大佬 : a719114136

    @w9ay
    @xJogger
    @deorth

    有个现成的库可以用 -> https://github.com/gojuukaze/terminal_layout ,图片加载不出来的话可以看 4 的链接

  • 資深大佬 : Yinz

    很久以前也解决过这个问题,做成了一个小库,不过因为工作忙没太维护,windows 会有问题,mac 和 linux 的应该是好的。
    https://github.com/Yinzo/reprint
    欢迎 PR

  • 資深大佬 : nanfangzai

    哈哈哈 我也做过这个东西

  • 資深大佬 : KentY

    好多年前写了一个. 你可以看下:
    https://github.com/sk1418/progressbar
    用起来就是这样的:
    https://github.com/sk1418/zhuaxia#screenshots

  • 資深大佬 : Akkuman

    哈哈,我也做过这个,这个好像 windows 上面是需要调用特定的 api,和其他的不太一样

  • 資深大佬 : CallMeReznov

    进度条? 我记得 python 是有个进度条的库的

  • 主 資深大佬 : lswang

    @xJogger 你用的 terminal 有问题吧,你的代码我可以运行

  • 資深大佬 : xJogger

    @lswang 我在 Windows 上用 cmd 运行的,你用的啥呀。

  • 主 資深大佬 : lswang

    @xJogger windows 的 cmd 估计是不行,你用 git 的那个 cmd 试试呢

文章導覽

上一篇文章
下一篇文章

AD

其他操作

  • 登入
  • 訂閱網站內容的資訊提供
  • 訂閱留言的資訊提供
  • WordPress.org 台灣繁體中文

51la

4563博客

全新的繁體中文 WordPress 網站
返回頂端
本站採用 WordPress 建置 | 佈景主題採用 GretaThemes 所設計的 Memory
4563博客
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?
在這裡新增小工具