Query regarding sys.stdout.write

Sreenath Nair sreenath.cg at gmail.com
Sun Jun 7 17:17:24 EDT 2015


Hi,

I have a general query about the following snippet:

import os
Import sys
for each_dir in os.listdir("/home/tmpuser"):
    full_path = os.path.join("/home/tmpuser", each_dir)
    sys.stdout.write("\r%s" % full_path)
    sys.stdout.flush()

The snippet is a simplified example of me trying to print to the same line by using carriage return. This is working fine. However, the issue is that if the previous line was longer than the current line being printed then there are characters leftover from the previous print. Like so:

Print no. 1: /home/tmpuser/somedir/somefile.ext
Print no. 2:/home/tmpuser/somefile.extmefile.ext

In case of the newly printed shorter line, the characters from the previously printed longer line are leftover... Is there any way to clear the previous print? While still being able to print to the same line?


Thank you for any help.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20150608/aa16b1c1/attachment.html>


More information about the Python-list mailing list