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


Groups > comp.lang.python > #92310

Re: Query regarding sys.stdout.write

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <cameron@cskk.homeip.net>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'subject:skip:s 10': 0.05; 'sufficient': 0.05; 'sys': 0.05; 'prefix': 0.07; 'logic': 0.09; 'newly': 0.09; 'overwrite': 0.09; 'snippet': 0.09; '>in': 0.16; 'carriage': 0.16; 'certainly.': 0.16; 'emit': 0.16; 'from:addr:cs': 0.16; 'from:addr:zip.com.au': 0.16; 'from:name:cameron simpson': 0.16; 'message-id:@cskk.homeip.net': 0.16; 'node.': 0.16; 'received:211.29': 0.16; 'received:211.29.132': 0.16; 'received:cskk.homeip.net': 0.16; 'received:homeip.net': 0.16; 'received:optusnet.com.au': 0.16; 'received:syd.optusnet.com.au': 0.16; 'simplified': 0.16; 'simpson': 0.16; 'subject:Query': 0.16; 'worst': 0.16; 'wrote:': 0.16; 'to:name:python-list@python.org': 0.20; 'trying': 0.22; 'cheers,': 0.24; 'header:In-Reply-To:1': 0.24; 'previously': 0.24; 'example': 0.25; 'header:User-Agent:1': 0.26; 'skip:2 30': 0.29; 'spaces': 0.29; 'minimal': 0.31; 'query': 0.31; 'print': 0.31; 'embedded': 0.32; 'common': 0.33; 'received:com.au': 0.33; 'shorter': 0.33; 'subject:regarding': 0.33; 'previous': 0.34; 'to:addr:python-list': 0.35; 'clear': 0.35; 'skip:o 20': 0.35; 'being': 0.36; 'there': 0.36; 'subject:: ': 0.37; 'charset:us- ascii': 0.37; 'ones': 0.38; 'updated': 0.38; 'end': 0.39; 'to:addr:python.org': 0.39; 'where': 0.40; 'content- disposition:inline': 0.60; 'back': 0.61; 'cameron': 0.66; 'notices': 0.66; 'points,': 0.84; 'skip:/ 30': 0.84
Date Mon, 8 Jun 2015 08:40:42 +1000
From Cameron Simpson <cs@zip.com.au>
To "python-list@python.org" <python-list@python.org>
Subject Re: Query regarding sys.stdout.write
MIME-Version 1.0
Content-Type text/plain; charset=us-ascii; format=flowed
Content-Disposition inline
In-Reply-To <BLU402-EAS68B18DD7A88AF142BC67B7E3B00@phx.gbl>
User-Agent Mutt/1.5.23 (2014-03-12)
References <BLU402-EAS68B18DD7A88AF142BC67B7E3B00@phx.gbl>
X-Optus-CM-Score 0
X-Optus-CM-Analysis v=2.1 cv=ItbjC+Lg c=1 sm=1 tr=0 a=rgDbx50tNA2z7xLXQOoruw==:117 a=rgDbx50tNA2z7xLXQOoruw==:17 a=ZtCCktOnAAAA:8 a=PO7r1zJSAAAA:8 a=J0QyKEt1u0cA:10 a=kj9zAlcOel0A:10 a=vrnE16BAAAAA:8 a=XAFQembCKUMA:10 a=pGLkceISAAAA:8 a=0i2GCV9zm2kTzTFr_nYA:9 a=CjuIK1q_8ugA:10
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.279.1433716866.13271.python-list@python.org> (permalink)
Lines 29
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1433716866 news.xs4all.nl 2854 [2001:888:2000:d::a6]:35305
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:92310

Show key headers only | View raw


On 08Jun2015 02:47, Sreenath Nair <sreenath.cg@gmail.com> 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?

Certainly. Keep track of the length of the previous line. Pad the new line with 
sufficient spaces to overwrite the old line, and then sufficient backspaces to 
get back to the end of the new line.

For added points, write a minimal updated that notices if the old line had a 
common prefix with the new line, and emit only the change.

Cheers,
Cameron Simpson <cs@zip.com.au>

The worst tyrannies were the ones where a governance required its own logic on
every embedded node. - Vernor Vinge

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Query regarding sys.stdout.write Cameron Simpson <cs@zip.com.au> - 2015-06-08 08:40 +1000

csiph-web