Skip to main content

Helpful functions for python.

Project description

Statusbar for Python for/while loops

Prepared by: Daniel A Hagen
Build Status PEP8 Coverage Status

Installation

pip install danpy

Installation from GitHub

git clone https://github.com/danhagen/danpy.git && cd danpy
pip install -r requirements.txt
pip install .

Example usage:

Initialize statusbar before running a for/while loop.

from danpy.sb import *
from time import sleep

SB = dsb()
N_loops = 10
for i in range(N_loops):
  sleep(0.5)
  SB.statusbar(i,N_loops,Title="Test Loop")

It is useful to either reset the statusbar instance. However, loops run in succession will automatically reset if the loops are of the same size.

from danpy.sb import *
from time import sleep

SB = dsb()
N_loops = 10
for j in range(3):
  for i in range(N_loops):
    sleep(0.5)
    SB.statusbar(i,N_loops,Title="Testing Loop-D-Loops")

for i in range(N_loops):
  sleep(0.5)
  SB.statusbar(i,N_loops,Title="Test Another Loop")

Resetting Statusbar

from danpy.sb import *
from time import sleep

SB = dsb()
N_loops = 10
for i in range(N_loops):
  sleep(0.5)
  SB.statusbar(i,N_loops,Title="Testing One Loop")

SB.reset_dsb()
N_loops = 20
for i in range(N_loops):
  sleep(0.5)
  SB.statusbar(i,N_loops,Title="Test A Different Loop")

Using while Loops

If using a while loop, the statusbar will still update, but depending on the nature of the code in the loop, the extrapolation to determine time remaining may be off.

from danpy.sb import *
from time import sleep

SB = dsb()
count = 0
N_loops = 10
while count<=N_loops:
  sleep(0.5)
  SB.statusbar(count,N_loops,Title="Testing One Loop")
  count+=1

Only compatible with while loops that utilize a count metric where the loop continues while count<N_loops. The "<" ensures that the statusbar terminates at 100%. If you use "<=" then the input to the statusbar will be SB.statusbar(i,N_loops+1,**kwargs).

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

danpy-0.0.5.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

danpy-0.0.5-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

Details for the file danpy-0.0.5.tar.gz.

File metadata

  • Download URL: danpy-0.0.5.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for danpy-0.0.5.tar.gz
Algorithm Hash digest
SHA256 eaf236f3fbc9b2965e7835a30c8934f56b0e3b8f05a35f07f28790c7946fa788
MD5 3b9c525027f9e5c5ee7f6ed85095c24f
BLAKE2b-256 61952dfdecefa47146b7ca5c1705d980deb9c38c1042aa9c3b803bdbf2a8e290

See more details on using hashes here.

File details

Details for the file danpy-0.0.5-py3-none-any.whl.

File metadata

File hashes

Hashes for danpy-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 a1f3d3aef296dee46ec7c721e3767fc62fa19a27b9608c4fcd149e304fa5a028
MD5 7f89a8d086f3444b794177222f890e17
BLAKE2b-256 4ab87778d58097faa4558658c4bfc1071ec9cb5761a29a6d750f2aedb16aa52a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page