256 Kilobytes

Answers in Scripting and Automation | By August R. Garcia

Published 2 months agoSun, 25 Aug 2019 12:04:00 -0700 | Last update 2 months agoSun, 25 Aug 2019 12:06:08 -0700

80 views, 0 RAMs, and 0 comments

Tags: Python, Progress Bars

Profile Photo - August R. Garcia August R. Garcia LARPing as a Sysadmi... Portland, OR
🗎 198 🗨 985 🐏 299
Site Owner

Commentary is hard. Use your reading skills to read this code:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import time
import sys
from   termcolor   import colored

def basic_progress_bar(current, end, num_chars=100):
        if (   (not isinstance(current, int) and not isinstance(current, float))  or  (not isinstance(end, int) and not isinstance(end, float))   ):
                return colored("??? / ???", 'red')

        if current > end:
                current = end

        percent   = ( float(current) / float(end)  )

        percent_complete   = int((num_chars*percent)  )
        percent_incomplete = num_chars - percent_complete

        #pb  = str(current).zfill( + " "
        pb  = str( int(percent*100)  ).rjust(3) + "%  "
        pb += "=" *percent_complete

        if (percent < 1.00): pb += "~" * (1)
        else:                pb += "=" * (1)

        pb += "-" * percent_incomplete
        pb += " "

        t   = len(str(end))
        pb += str(int(current)).rjust(t) + " out of " + str(int(end)).rjust(t)
        return pb


# Demo usage 
while True:
        c = 0.000
        sys.stdout.write(basic_progress_bar(c, 60) +"\r") ; sys.stdout.flush()
        while c < 60:
                c += random.uniform(0,1)
                sys.stdout.write(basic_progress_bar(c, 60) +"\r") ; sys.stdout.flush()
                time.sleep(0.01)
        print ""
        time.sleep(1)
Download more RAM. 🐏 ⨉ 0 Posted by August R. Garcia 2 months ago

Edit History

• [2019-08-25 12:04 PDT] August R. Garcia (2 months ago)
• [2019-08-25 12:04 PDT] August R. Garcia (2 months ago)
🕓 Posted at 25 August, 2019 12:04 PM PDT

Sir, I can do you a nice SEO.

Post a New Comment

To leave a comment, login to your account or create an account.

Do you like having a good time?

Read Quality Articles

Read some quality articles. If you can manage to not get banned for like five minutes, you can even post your own articles.

View Articles →

Argue with People on the Internet

Use your account to explain why people are wrong on the Internet forum.

View Forum →

Vandalize the Wiki

Or don't. I'm not your dad.

View Wiki →

Ask and/or Answer Questions

If someone asks a terrible question, post a LMGTFY link.

View Answers →

Make Some Money

Hire freelancers and/or advertise your goods and/or services. Hire people directly. We're not a middleman or your dad. Manage your own business transactions.

Register an Account
You can also login to an existing account or recover your password. All use of this site is subject to terms outlined in the terms of service and privacy policy.