Re: [問題] command line 印出字串(固定位置)
※ 引述《rorp (RORP)》之銘言:
: 請問一下各位高手,
: 假如我想要在命令提示字元輸出字串
: 字串會隨著迴圈更新
: 例如:
: for n in range(1,200):
: print 'number:',n
: 結果是:
: number: 1
: number: 2
: number: 3
: .
: .
: .
: 可是這樣不好看,假如我更新2000次,就有兩千行了
: 有沒有辦法輸出字串是在同一個位置更新的
: 想要的結果:
: number: n <==在同一個位置,不另起新行,n會隨著時間更新。
: 感謝各位解惑!
Unix 系列的平台上可以使用 curses module。
http://docs.python.org/library/curses.html#module-curses
Windows 平台可以透過 ctypes 來調用 kernel32 裡控制 console 的 API。
底下是一些透過 ctypes 做好的 wrapper function:(conio.py)
(可以直接執行之先看看 demo 效果)
http://paste.plurk.com/show/148537
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 218.173.139.116
推
01/22 19:10, , 1F
01/22 19:10, 1F
→
01/23 00:28, , 2F
01/23 00:28, 2F
→
01/23 20:16, , 3F
01/23 20:16, 3F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):
Python 近期熱門文章
PTT數位生活區 即時熱門文章