作者sbrhsieh (偶尔想摆烂一下)
看板Python
标题Re: [问题] command line 印出字串(固定位置)
时间Fri Jan 22 13:35:21 2010
※ 引述《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
1F:推 rexrainbow:满酷的范例 01/22 19:10
2F:→ rorp:感谢! 范例很有趣! 01/23 00:28
3F:→ kingjoe:若是windows平台的话使用WConio套件还方便的 01/23 20:16