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


Groups > comp.lang.python > #79180

Re: Creating a counter

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <gary.herron@islandtraining.com>
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.05; 'plenty': 0.07; 'string': 0.09; 'received:67.192': 0.09; 'received:67.192.241': 0.09; 'received:dfw.emailsrvr.com': 0.09; 'skip:/ 10': 0.09; 'python': 0.11; 'comma': 0.16; 'confuse': 0.16; 'count,': 0.16; 'displaying': 0.16; 'increment': 0.16; 'overwriting': 0.16; 'thanks,': 0.17; 'wrote:': 0.18; 'trying': 0.19; 'seems': 0.21; 'print': 0.22; 'header:User-Agent:1': 0.23; 'received:emailsrvr.com': 0.24; 'question': 0.24; 'script': 0.25; 'received:(smtp server)': 0.26; 'second': 0.26; 'asking': 0.27; 'values': 0.27; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'statement': 0.30; 'gary': 0.31; 'prints': 0.31; 'alone': 0.33; 'usual': 0.35; 'but': 0.35; 'found.': 0.36; 'hi,': 0.36; 'should': 0.36; 'list': 0.37; 'received:10': 0.37; 'implement': 0.38; 'writes': 0.38; 'to:addr:python-list': 0.38; 'files': 0.38; 'itself': 0.39; 'to:addr:python.org': 0.39; 'how': 0.40; 'new': 0.61; 'finish': 0.65; 'charset:windows-1252': 0.65; 'within': 0.65; 'received:10.10': 0.74; 'ending': 0.78
X-Virus-Scanned OK
X-Sender-Id gary.herron@islandtraining.com
Date Wed, 15 Oct 2014 13:04:03 -0700
From Gary Herron <gary.herron@islandtraining.com>
User-Agent Mozilla/5.0 (X11; Linux x86_64; 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>
In-Reply-To <loom.20141015T203348-999@post.gmane.org>
Content-Type text/plain; charset=windows-1252; format=flowed
Content-Transfer-Encoding 7bit
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.14898.1413403937.18130.python-list@python.org> (permalink)
Lines 40
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1413403937 news.xs4all.nl 2922 [2001:888:2000:d::a6]:58316
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:79180

Show key headers only | View raw


On 10/15/2014 11:39 AM, Shiva wrote:
> 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.
>
> Thanks,
> Shiva
>

The question seems confuse the word "increment".

If you are asking how to count, plenty of responders have answered
     count = count+1
and similar.

However, the second paragraphs seems to use the word "increment" to mean 
displaying the counter on a single line overwriting itself instead of a 
scrolling list of values one-per-line.  The solution may depend on what 
is displaying the value as you write it out, but if it's a 
terminal/command-prompt /console-window, then you want the write to 
finish with a carriage-return alone instead of a 
carriage-return/new-line combination.  In Python that is represented 
with a \r instead of a \n.

Python2:
   print counter, '\r', # The ending comma means do NOT output the usual \n

Python3:
   print(counter, end='\r')

Gary Herron

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


Thread

Re: Creating a counter Gary Herron <gary.herron@islandtraining.com> - 2014-10-15 13:04 -0700

csiph-web