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


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

Re: Creating a counter

Started byVincent Vande Vyvre <vincent.vande.vyvre@telenet.be>
First post2014-10-15 21:24 +0200
Last post2014-10-15 21:24 +0200
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 Vincent Vande Vyvre <vincent.vande.vyvre@telenet.be> - 2014-10-15 21:24 +0200

#79177 — Re: Creating a counter

FromVincent Vande Vyvre <vincent.vande.vyvre@telenet.be>
Date2014-10-15 21:24 +0200
SubjectRe: Creating a counter
Message-ID<mailman.14895.1413401793.18130.python-list@python.org>
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.
>
> Thanks,
> Shiva
>
Try this:

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


Vincent.

[toc] | [standalone]


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


csiph-web