The Tech Edvocate

Top Menu

  • Advertisement
  • Apps
  • Home Page
  • Home Page Five (No Sidebar)
  • Home Page Four
  • Home Page Three
  • Home Page Two
  • Home Tech2
  • Icons [No Sidebar]
  • Left Sidbear Page
  • Lynch Educational Consulting
  • My Account
  • My Speaking Page
  • Newsletter Sign Up Confirmation
  • Newsletter Unsubscription
  • Our Brands
  • Page Example
  • Privacy Policy
  • Protected Content
  • Register
  • Request a Product Review
  • Shop
  • Shortcodes Examples
  • Signup
  • Start Here
    • Governance
    • Careers
    • Contact Us
  • Terms and Conditions
  • The Edvocate
  • The Tech Edvocate Product Guide
  • Topics
  • Write For Us
  • Advertise

Main Menu

  • Start Here
    • Our Brands
    • Governance
      • Lynch Educational Consulting, LLC.
      • Dr. Lynch’s Personal Website
      • Careers
    • Write For Us
    • The Tech Edvocate Product Guide
    • Contact Us
    • Books
    • Edupedia
    • Post a Job
    • The Edvocate Podcast
    • Terms and Conditions
    • Privacy Policy
  • Topics
    • Assistive Technology
    • Child Development Tech
    • Early Childhood & K-12 EdTech
    • EdTech Futures
    • EdTech News
    • EdTech Policy & Reform
    • EdTech Startups & Businesses
    • Higher Education EdTech
    • Online Learning & eLearning
    • Parent & Family Tech
    • Personalized Learning
    • Product Reviews
  • Advertise
  • Tech Edvocate Awards
  • The Edvocate
  • Pedagogue
  • School Ratings

logo

The Tech Edvocate

  • Start Here
    • Our Brands
    • Governance
      • Lynch Educational Consulting, LLC.
      • Dr. Lynch’s Personal Website
        • My Speaking Page
      • Careers
    • Write For Us
    • The Tech Edvocate Product Guide
    • Contact Us
    • Books
    • Edupedia
    • Post a Job
    • The Edvocate Podcast
    • Terms and Conditions
    • Privacy Policy
  • Topics
    • Assistive Technology
    • Child Development Tech
    • Early Childhood & K-12 EdTech
    • EdTech Futures
    • EdTech News
    • EdTech Policy & Reform
    • EdTech Startups & Businesses
    • Higher Education EdTech
    • Online Learning & eLearning
    • Parent & Family Tech
    • Personalized Learning
    • Product Reviews
  • Advertise
  • Tech Edvocate Awards
  • The Edvocate
  • Pedagogue
  • School Ratings
  • US Battery as a Service Market Shifts Toward Fleet-Based Energy

  • The Startling Truth: Why Americans Distrust AI with Their Health

  • This Crucial Deadline for Banks Is Closer Than You Think

  • Baffling: CrowdStrike’s $500 Million AI Bet Reshapes Cybersecurity

  • This Crucial Autonomous Driving Rule Could Cost You Everything

  • Baffling: Microsoft AI CEO Demands Halt to Conscious AI Development

  • O seară în ritmul tău: atmosfera divertismentului de cazinou pe internet

  • Outrageous: AppLovin Hit With Lawsuit Over AI Claims — What Investors Need to Know

  • 9 Critical Ways AI Investment Fraud Is Quietly Draining Your Bank Account

  • Is the AI Bubble Bursting? OpenAI’s Funding Woes Revealed

Digital & Mobile Technology
Home›Digital & Mobile Technology›Create a Progress Bar in Python CLI

Create a Progress Bar in Python CLI

By Matthew Lynch
August 3, 2023
0
Spread the love

As a Python developer, you may need to display results of your scripts on a console. One way to enhance the user experience is to display a progress bar, especially if our script takes long to run. In this article, we will learn how to create a progress bar in Python CLI.

First, let us look at a simplistic way of displaying a progress bar. Consider the following script that takes a long time to run:

“`
import time

for i in range(0, 101):
time.sleep(0.1)
print(i)
“`

The script simply counts from 0 to 100 and waits for 0.1 seconds before printing the next count. While this is running, let us assume that we want to display the progress of the script in the following format: `[####——–] 40%`

To achieve this, we need the following:

1. A counter that keeps track of the progress of our script
2. A string representation of the progress bar that we can update as the script runs.
3. A way of printing the progress bar and updating it as the script runs.

Let’s implement the above-mentioned requirements:

“`
import time

def progress(count, total, status=”):
bar_len = 60
filled_len = int(round(bar_len * count / float(total)))

percents = round(100.0 * count / float(total), 1)
bar = ‘#’ * filled_len + ‘-‘ * (bar_len – filled_len)

print(‘[%s] %s%s %s\r’ % (bar, percents, ‘%’, status), end=”)

total = 100
for i in range(1, total + 1):
time.sleep(0.1)
progress(i, total)
“`

The `progress` function takes in three arguments:

1. `count`: the current count of the script
2. `total`: the total number of iterations
3. `status`: any additional messages you want to display while the script runs.

The function calculates the percentage completed by dividing `count` by `total`. It then creates a string representation of the progress bar using the `bar` and `filled_len` variables.

The output of the function is then printed to the console, with the `\r` character included to ensure that the output overwrites any previous output.

Finally, we call the `progress` function within the for loop, passing in the `i` and `total` values to calculate progress.

We have effectively implemented a progress bar in Python CLI. You can run this script on any long-running script to enhance the user experience.

In conclusion, the progress bar is an essential tool for enhancing the user experience when running long scripts. By displaying the progress of the script in a visual way, users can track the progress of a script. In Python, creating the progress bar is straightforward, and with the implementation we have discussed in this article, Python developers can easily add progress bars to their CLI-based applications.

Previous Article

Which GPU Should You Choose? Nvidia RTX ...

Next Article

The 5 Best Free Auto Subtitle Generators ...

Matthew Lynch

Related articles More from author

  • Digital & Mobile Technology

    iPhone 13 Pro Max vs. iPhone 14 Pro Max: Did Apple’s Biggest iPhone Improve?

    June 8, 2023
    By Matthew Lynch
  • Digital & Mobile Technology

    Can You Mine Crypto On Apple M1 or M2 Silicon?

    June 14, 2023
    By Matthew Lynch
  • Digital & Mobile Technology

    Everything You Need to Know About POP

    July 24, 2023
    By Matthew Lynch
  • Digital & Mobile Technology

    Is Hibernate Mode Bad for Your PC?

    June 12, 2023
    By Matthew Lynch
  • Digital & Mobile Technology

    Best Translation Apps of 2023

    June 6, 2023
    By Matthew Lynch
  • Digital & Mobile Technology

    Samsung Wows With Foldable and Slidable Displays That Extend to New Lengths

    July 6, 2023
    By Matthew Lynch

Search

Login & Registration

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org

Newsletter

Signup for The Tech Edvocate Newsletter and have the latest in EdTech news and opinion delivered to your email address!

About Us

Since technology is not going anywhere and does more good than harm, adapting is the best course of action. That is where The Tech Edvocate comes in. We plan to cover the PreK-12 and Higher Education EdTech sectors and provide our readers with the latest news and opinion on the subject. From time to time, I will invite other voices to weigh in on important issues in EdTech. We hope to provide a well-rounded, multi-faceted look at the past, present, the future of EdTech in the US and internationally.

We started this journey back in June 2016, and we plan to continue it for many more years to come. I hope that you will join us in this discussion of the past, present and future of EdTech and lend your own insight to the issues that are discussed.

Newsletter

Signup for The Tech Edvocate Newsletter and have the latest in EdTech news and opinion delivered to your email address!

Contact Us

The Tech Edvocate
910 Goddin Street
Richmond, VA 23231
(601) 630-5238
[email protected]

Copyright © 2026 Matthew Lynch. All rights reserved.