Creating a counter

Vincent Vande Vyvre vincent.vande.vyvre at telenet.be
Wed Oct 15 15:24:27 EDT 2014


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.



More information about the Python-list mailing list