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


Groups > comp.lang.python > #79177

Re: Creating a counter

Date 2014-10-15 21:24 +0200
From Vincent Vande Vyvre <vincent.vande.vyvre@telenet.be>
Subject Re: Creating a counter
References <loom.20141015T203348-999@post.gmane.org>
Newsgroups comp.lang.python
Message-ID <mailman.14895.1413401793.18130.python-list@python.org> (permalink)

Show all headers | View raw


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.

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


Thread

Re: Creating a counter Vincent Vande Vyvre <vincent.vande.vyvre@telenet.be> - 2014-10-15 21:24 +0200

csiph-web