Skip to main content

Helpful functions for python.

Project description

Collection of useful python functions/features.

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:

Statusbar for Python for/while loops with danpy.sb

This helpful statusbar can be used with for/while loops to keep track of how much time has elapsed as well as how much time remains. Simply place inside the loop (after initializing the statusbar -- dsb) and update with the current timestep (i). A title can be added to the statusbar to keep track of individual function/loops and it is recommended that any function that runs a loop uses arbitrary_function_name.__name__ to automatically assign an appropriate title.

Initialize statusbar before running a for/while loop.

from danpy.sb import *
from time import sleep

statusbar = dsb()
number_of_loops = 10
for i in range(number_of_loops):
  sleep(0.5)
  statusbar.update(i,number_of_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

statusbar = dsb()
number_of_inside_loops = 10
number_of_outside_loops = 3
for j in range(number_of_outside_loops):
  for i in range(number_of_inside_loops):
    sleep(0.5)
    statusbar.update(i,number_of_inside_loops,title="Testing Loop-D-Loops")

number_of_additional_loops = 10
for i in range(number_of_additional_loops):
  sleep(0.5)
  statusbar.update(i,number_of_additional_loops,title="Test Another Loop")

Resetting Statusbar

from danpy.sb import *
from time import sleep

statusbar = dsb()
number_of_loops = 10
for i in range(number_of_loops):
  sleep(0.5)
  statusbar.update(i,number_of_loops,title="Testing One Loop")

statusbar.reset()
a_different_number_of_loops = 20
for i in range(a_different_number_of_loops):
  sleep(0.5)
  statusbar.update(i,a_different_number_of_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

statusbar = dsb()
count = 0
number_of_loops = 10
while count<=number_of_loops:
  sleep(0.5)
  statusbar.update(count,number_of_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.1.0.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

danpy-0.1.0-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for danpy-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6ffe2fff71e23a6f235ba0d2aa2093d7a8a3fbc65dcb54bad03c3b19b5304c7a
MD5 6245a416e21e931e98f1a27cb144fc64
BLAKE2b-256 b47691cb95ccb32daacfe639b61d756d414267af0500191311a7ea005c9b5114

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for danpy-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e884c3fc96c61a61821857b593c3c2d19fc8c1bb11850e1f7d02603752394d6a
MD5 0d6d9a33dfcfe51f6cc798019a91c418
BLAKE2b-256 22dce0fbb42c43b9b3e2ba39e0a46ade2ed6bdd51be383edb132255ea045d9f7

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