简体   繁体   中英

python stdout carriage return

i am running a for loop on a given set of files..and for monitoring purpose it writes output on which files are being currently processed..

sys.stdout.write("\rProcessing.... "+ j)
sys.stdout.flush()

where j is filenames

output of script...

Processing.... /etc/sysconfig/rhn/sources0.examplewn-slepcsbals-ipv6f

problem is that the carriage return "\\r" does not clear the previous filename clearly and has previous filenames on it.

any idea how i can fix this..and make it more clear

Remember the written string, and write spaces first.

sys.stdout.write('\r' + (' ' * len(old_string)))
sys.stdout.write('\rProcessing... ' + new_string)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM