Created
April 22, 2019 16:20
-
-
Save lampholder/e61120ed4517d308533722fab143cd11 to your computer and use it in GitHub Desktop.
Partial Unicode blocks progress bar in python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def progress(percent, width=20, blocks=['', '▏','▎','▍','▌','▋','▊','▉','█']): | |
return '{:<{width}}'.format(int(min(percent, 1) * width) * blocks[-1] + | |
blocks[int(min(percent, 1) * width * len(blocks) % len(blocks))], width=width) |
Or, if your terminal can't handle utf-8:
if not sys.stdout.encoding.lower().startswith('utf')
consider:
blocks=['', '1', '2', '3', '4', '5', '6', '7', '8', '9', '#']
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The first element in the blocks array should always be emptystring.