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


Groups > comp.lang.python > #79178

Re: Creating a counter

X-FeedAbuse http://nntpfeed.proxad.net/abuse.pl feeded by 78.192.65.63
Path csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!news.muarf.org!news.ecp.fr!feeder1.cambriumusenet.nl!feed.tweaknews.nl!194.109.133.86.MISMATCH!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python@mrabarnett.plus.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.006
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'string': 0.09; '%s"': 0.09; 'cursor': 0.09; 'python': 0.11; 'def': 0.12; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'increment': 0.16; 'message- id:@mrabarnett.plus.com': 0.16; 'newline,': 0.16; 'received:192.168.1.4': 0.16; 'wrote:': 0.18; 'trying': 0.19; 'normally': 0.19; '>>>': 0.22; 'print': 0.22; 'header:User- Agent:1': 0.23; 'specify': 0.24; 'script': 0.25; 'this:': 0.26; 'header:In-Reply-To:1': 0.27; 'statement': 0.30; 'end,': 0.31; 'prints': 0.31; 'but': 0.35; 'found.': 0.36; 'hi,': 0.36; 'should': 0.36; 'implement': 0.38; 'writes': 0.38; 'to:addr :python-list': 0.38; 'files': 0.38; 'skip:. 10': 0.39; 'to:addr:python.org': 0.39; 'how': 0.40; 'new': 0.61; 'back': 0.62; 'within': 0.65; 'moves': 0.84
X-CM-Score 0.00
X-CNFS-Analysis v=2.1 cv=V9zz0IXi c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=0Bzu9jTXAAAA:8 a=m9fHe4oz-9sA:10 a=ihvODaAuJD4A:10 a=IkcTkHD0fZMA:10 a=EBOSESyhAAAA:8 a=9MehRHZ3cVDrtXVyoKEA:9 a=QEXdDO2ut3YA:10
X-AUTH mrabarnett:2500
Date Wed, 15 Oct 2014 20:48:30 +0100
From MRAB <python@mrabarnett.plus.com>
User-Agent Mozilla/5.0 (Windows NT 6.3; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.1.2
MIME-Version 1.0
To python-list@python.org
Subject Re: Creating a counter
References <loom.20141015T203348-999@post.gmane.org> <543EC9EB.8010202@telenet.be>
In-Reply-To <543EC9EB.8010202@telenet.be>
Content-Type text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding 8bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
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.14896.1413402701.18130.python-list@python.org> (permalink)
Lines 39
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1413402701 news.xs4all.nl 2836 [2001:888:2000:d::a6]:52333
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:79178

Show key headers only | View raw


On 2014-10-15 20:24, Vincent Vande Vyvre wrote:
> Le 15/10/2014 20:39, Shiva a écrit :
>> Hi,
>>
>> I am trying to search a string through files in a directory -
>> however while Python script works on it and writes a log - I want
>> to present the user with count of number of strings found. So it
>> should increment for each string found.
>>
>> How do I implement it?
>>
>> If I use a print() within a if condition statement - and execute
>> the script in terminal - for each find, the print() prints in new
>> line instead of a constantly incrementing counter.
>>
 > Try this:
 >
 >   >>> def counter(x):
 > ...     for i in range(x):
 > ...             print "\rProgress .............. %s" % i,
 > ...             sys.stdout.flush()
 > ...             time.sleep(1)
 > ...
 >   >>> counter(5)
 >
In Python 3, you can specify what to do at the end of the print.
Normally it prints a newline, but you can make it print nothing at the
end, leaving the cursor just after the last thing printed:

 >>> def counter(x):
...     for i in range(x):
...         print("\rProgress .............. %s" % i, end="")
...         sys.stdout.flush()
...         time.sleep(1)
...
 >>> counter(5)

The "\r" moves the cursor back to the start of the line so that it
overwrites what was printed last time.

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


Thread

Re: Creating a counter MRAB <python@mrabarnett.plus.com> - 2014-10-15 20:48 +0100

csiph-web