How to create a progress bar in Python

How to create a progress bar in Python

Python
Creating a progress bar is really useful if you have a long-running task and you'd like to know how far along you are. In this post we'll talk about two packages for creating progress bars in Python: tqdm and progressbar2. Creating a progress bar with Python's tqdm package Let's get started by installing tqdm. We can do that using pip: [code] pip install tqdm [/code] Once we have tqdm installed, it's straightforward to use. Essentially, we just need to wrap whatever object we're looping over (i.e. any object that is iterable) inside tqdm. Then, when the code runs, Python will print out a progress bar so that you can know how far along you are. [code lang="python"] from tqdm import tqdm result = 0 for i in tqdm(range(10000000)): result +=…
Read More
Timing Python Processes

Timing Python Processes

Python
Timing Python processes is made possible with several different packages. One of the most common ways is using the standard library package, time, which we'll demonstrate with an example. However, another package that is very useful for timing a process -- and particularly telling you how far along a process has come -- is tqdm. As we'll show a little further down the post, tqdm will actually print out a progress bar as a process is running. Basic timing example Suppose we want to scrape the HTML from some collection of links. In this case, we're going to get a collection of URLs from Bloomberg's homepage. To do this, we'll use BeautifulSoup to get a list of full-path URLs. From the code below, this gives us a list of around…
Read More