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


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

Re: Creating a counter

Started byGary Herron <gary.herron@islandtraining.com>
First post2014-10-15 13:04 -0700
Last post2014-10-15 13:04 -0700
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: Creating a counter Gary Herron <gary.herron@islandtraining.com> - 2014-10-15 13:04 -0700

#79180 — Re: Creating a counter

FromGary Herron <gary.herron@islandtraining.com>
Date2014-10-15 13:04 -0700
SubjectRe: Creating a counter
Message-ID<mailman.14898.1413403937.18130.python-list@python.org>
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

[toc] | [standalone]


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


csiph-web