2

As part of my script I am printing to the console. I'd really like to print onto the same line but dynamically. e.g.

Something like

1, 2,

1, 2, 3,

1, 2, 3, 4 

I have tried:

logging.info("Deleting rows...");
for i in range(0, sizeOfFeed):
    logging.info("\%d"  % i);

Put this just does

\0
\1
\2

It's dynamic but on different lines.

Any tips

Sven Marnach
  • 574,206
  • 118
  • 941
  • 841
dublintech
  • 16,815
  • 29
  • 84
  • 115
  • 1
    I don't understand the question. What printable stuff do you have and what is the function that governs the dynamicity of the printing out? – inspectorG4dget Feb 10 '12 at 16:23

2 Answers2

4

Store the line to be printed. Print a \r then the line, then flush. Change the line, then repeat.

Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
  • Works for me (although the OP will have to take care not to print a trailing newline). – DSM Feb 10 '12 at 16:27
3
from sys import stdout
from time import sleep
for i in range(1,20):
    stdout.write("\r%d" % i)
    stdout.flush()
    sleep(1)
stdout.write("\r  \r\n") # clean up

\r is a special char: carriage return, in old typing machine it locate the cursor at the begin of line

Alberto
  • 2,881
  • 7
  • 35
  • 66