Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!feed.xsnews.nl!border-1.ams.xsnews.nl!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'output': 0.04; '%s"': 0.07; 'msg': 0.07; 'scripts': 0.09; 'formatted': 0.09; 'sep': 0.09; 'whole,': 0.09; '10:05': 0.16; 'enough.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'say)': 0.16; 'string': 0.17; 'wrote:': 0.17; 'previously': 0.18; 'received:209.85.214.174': 0.21; 'random': 0.24; 'header:In-Reply- To:1': 0.25; 'am,': 0.27; 'question': 0.27; 'message- id:@mail.gmail.com': 0.27; 'fixed': 0.28; 'subject:/': 0.28; 'spaces': 0.29; 'case,': 0.29; 'fri,': 0.30; 'function': 0.30; 'print': 0.32; 'done,': 0.33; 'to:addr:python-list': 0.33; 'received:google.com': 0.34; 'list': 0.35; 'received:209.85': 0.35; 'add': 0.36; 'but': 0.36; 'method': 0.36; 'should': 0.36; 'enough': 0.36; 'received:209': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'received:209.85.214': 0.39; 'header:Received:5': 0.40; 'effective': 0.63; 'increase': 0.72; 'wipe': 0.84; 'total,': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=OhQFvaKUSe1YFBKEZZyuzuWV2FLMXPela8op+BgLR5k=; b=xldQ0QITY1+aCMMRuQgPCV3P6hU/ts/jzuBkhzFvOPdC2PEouwcqSGq9wI4I0PRZzS UTUOzqksL6K7VpZUx62NtsIQYwlJMeRrMS2B3f+wiw6oDsGOnzgUTkJ/t+YqIcvP/Y7/ awVZDkvBEsJflKD81jFtg6CwZvXD1QZUSm4/xp+3yGGitb89m/H7nFPBajeZ5NyULuQZ ZlHp5SwmixGcNh5zuHOLgooZFU030R1nAfTGp2Smx08oKnx6C35DNazUXDip/YB75yPG ZVhLRleKx51ViCDRavWG9/8SpAZlAjmyMScXvZ4y6YLOkJNPk/ShJ5B46gziS2BiIjsQ ajaA== MIME-Version: 1.0 In-Reply-To: <686fj9-aql.ln1@murmur.very.softly> References: <686fj9-aql.ln1@murmur.very.softly> Date: Fri, 28 Sep 2012 18:08:58 +1000 Subject: Re: Reducing cache/buffer for faster display From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 18 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1348819742 news.xs4all.nl 6903 [2001:888:2000:d::a6]:50846 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:30367 On Fri, Sep 28, 2012 at 10:05 AM, Rikishi42 wrote: > The scripts in question only increase numbers. But should that not be the > case, solutions are simple enough. The numbers can be formatted to have a > fixed size. In the case of random line contents (a list of filesnames, say) > it's enough to create an output function that is aware of the length of the > previously printed line, and add enough spaces to the current one to wipe > exess content. Yep, that's a pretty effective way to do it. One simple method to it is to format the whole string as a single whole, then left justify it in a field of (say) 79 characters, and output that: msg = "Progress: %d%% (%d/%d)... %s" % (done*100/total, done, total, current_file) print msg.ljust(79)+"\r", sys.stdout.flush() ChrisA