I would like to make several statements that give standard output without seeing newlines in between statements.
Specifically, suppose I have:
for it
Change print item
to:
print item,
in Python 2.7print(item, end=" ")
in Python 3If you want to print the data dynamically use following syntax:
print(item, sep=' ', end='', flush=True)
in Python 3To make the numbers overwrite each other, you can do something like this:
for i in range(1,100):
print "\r",i,
That should work as long as the number is printed in the first column.
EDIT: Here's a version that will work even if it isn't printed in the first column.
prev_digits = -1
for i in range(0,1000):
print("%s%d" % ("\b"*(prev_digits + 1), i)),
prev_digits = len(str(i))
I should note that this code was tested and works just fine in Python 2.5 on Windows, in the WIndows console. According to some others, flushing of stdout may be required to see the results. YMMV.