0

I'm coding a small Python script, that checks the records of a few domains. This is how I do it:

if results.short == True:
        isonlist = False
        for dnsbls in L:
                try:
                        if  socket.gethostbyname("%s.%s" % (ip_reversed(results.IP), dnsbls)).startswith("127"):
                                isonlist = True
                except (socket.gaierror):
                        pass
        if isonlist == True:
                print "1"
        else:
                print "0"

else:
        pass

Right now it outputs 1 if it get's a valid record and 0 if it doesn't.

Now, I'd like for it to show a progress bar, like when you use wget and the likes. Tried doing it like this:

number = number + 1

But that yields me 1 2 3 4 and so forth.

Mikko Ohtamaa
  • 82,057
  • 50
  • 264
  • 435
MadsRC
  • 139
  • 1
  • 3
  • 10
  • 1
    Possible duplicate of http://stackoverflow.com/questions/3002085/python-to-print-out-status-bar-and-percentage – mgilson Nov 06 '12 at 12:51
  • Possible duplicate of http://stackoverflow.com/questions/3173320/text-progress-bar-in-the-console/34325723#34325723 – Greenstick May 20 '16 at 20:24

3 Answers3

4

My personal favorite for this is python-progressbar. It's fast and easy to use.

mgilson
  • 300,191
  • 65
  • 633
  • 696
Johannes
  • 275
  • 3
  • 12
  • I am aware of Python-progressbar, but I was looking for some help implementing the code. While I can find a few things that will work by itself, I can't seem to successfully incorporate it into the above code. – MadsRC Nov 06 '12 at 13:39
1

Of course there are many progress bar implementation in Python. Some use curses or similar terminal libraries (example: http://nadiana.com/animated-terminal-progress-bar-in-python), other use simple sys.stdout.write('\rstep %d of %d' % (step, max_steps))

Notice usage of \r that means that text you write will replace current line content on console.

Also do not use number = number + 1, use number += 1

Michał Niklas
  • 53,067
  • 18
  • 70
  • 114
1

Giorgos Verigakis's has his more recent and rather nice https://github.com/verigak/progress.

tobych
  • 2,941
  • 29
  • 18
  • You can "pip install progress" and include it as a dependency, too. See also https://pypi.python.org/pypi/progress – gldnspud Jul 31 '13 at 21:04