printing unfinished line

Doug Stanfield DOUGS at oceanic.com
Sat Mar 25 12:52:52 EST 2000


You need to use flush.  This is an example where I was displaying an
incrementing counter on a text display to show progress:

import sys
Found,notFound = 0,0
print "\n"
for device in devices:
    # Do something, like searching in a text file
    print "\r",
    print "Device %s,  Found: %s, Not Found: %s, Total: %s." \
              % (device,Found,notFound,(Found + notFound)),
    sys.stdout.flush()
print "\nDone!"

HTH

-Doug-

> -----Original Message-----
> From: Gang Seong Lee [mailto:gslee111 at daisy.kwangwoon.ac.kr]
> Sent: Friday, March 24, 2000 9:08 PM
> To: python-list at python.org
> Subject: printing unfinished line
> 
> 
> Is there any way that I can see the output of a string not 
> having a new line
> char.
> For example,
> 
> import time
> 
> print 'abc',
> time.sleep(3)
> print 'def'
> 
> 'abc' is not displayed on the screen until it encounters last 
> print 'def',
> which has new line at the end of the line. sys.write('abc') 
> has the same
> effect.
> 
> Is it possible I can see 'abc' before it goes to print 'def' ?
> 
> Thank you
> 
> Gang
> 
> 
> -- 
> http://www.python.org/mailman/listinfo/python-list
> 




More information about the Python-list mailing list