Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #92313 > unrolled thread

Re: Query regarding sys.stdout.write

Started byCecil Westerhof <Cecil@decebal.nl>
First post2015-06-08 00:30 +0200
Last post2015-06-08 00:30 +0200
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Query regarding sys.stdout.write Cecil Westerhof <Cecil@decebal.nl> - 2015-06-08 00:30 +0200

#92313 — Re: Query regarding sys.stdout.write

FromCecil Westerhof <Cecil@decebal.nl>
Date2015-06-08 00:30 +0200
SubjectRe: Query regarding sys.stdout.write
Message-ID<874mmjnobq.fsf@Equus.decebal.nl>
On Sunday  7 Jun 2015 23:17 CEST, Sreenath Nair wrote:

> 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?

Say that you know that a line will never be longer as 80 characters,
then you could do something like:
sys.stdout.write('\r{0:80}'.format(full_path))

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web