MadsRC
MadsRC

Reputation: 139

Creating a progress bar/status in Python text console

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.

Upvotes: 0

Views: 6120

Answers (3)

tobych
tobych

Reputation: 2961

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

Upvotes: 1

Michał Niklas
Michał Niklas

Reputation: 54342

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

Upvotes: 1

Johannes
Johannes

Reputation: 275

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

Upvotes: 4

Related Questions