Skip to content

Instantly share code, notes, and snippets.

@lampholder
Created April 22, 2019 16:20
Show Gist options
  • Save lampholder/e61120ed4517d308533722fab143cd11 to your computer and use it in GitHub Desktop.
Save lampholder/e61120ed4517d308533722fab143cd11 to your computer and use it in GitHub Desktop.
Partial Unicode blocks progress bar in python
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)
@lampholder
Copy link
Author

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