Printing digits in one place
sjmachin at lexicon.net
Tue Nov 25 00:57:35 CET 2008
On Nov 25, 10:21 am, Oltmans <rolf.oltm... at gmail.com> wrote:
> I'm writing a file-transfer program and I'm receiving bytes
> transferred in a function. Now I would like to print bytes transfered
> in one place e.g.
> Bytes Transfered so far X
> and X will increase and cursor should stay at this position. I don't
> want to use any 3rd party module for this. Can I somehow do that
> without using any third-party module?
> I've been able to do this with Console module available athttp://effbot.org/zone/console-handbook.htmbut I would want to do
> this without the Console module. Actually , I'm able to initialize the
> Console module and print the bytes transferrred information but I
> can't find a way to exit from Console module so that my other
> functions can proceed with normal display using 'print' statement.
> Any ideas will be appreciated.
Try using backspaces e.g. something like this:
| >>> import time, sys
| >>> msg = ''
| >>> for i in range(15):
| ... time.sleep(2.0)
| ... nbs = len(msg)
| ... msg = str(i)
| ... sys.stdout.write('\b' * nbs + msg)
More information about the Python-list