Skip to content

Instantly share code, notes, and snippets.

@patillacode
Created April 23, 2019 10:53
Show Gist options
  • Save patillacode/3a9426fd9b6c580adf760964aec83efd to your computer and use it in GitHub Desktop.
Save patillacode/3a9426fd9b6c580adf760964aec83efd to your computer and use it in GitHub Desktop.
Python loading bar
def print_status_bar(number, number_of_pages):
percentage = int((number / number_of_pages) * 100)
progress = int((percentage * 20) / 100)
progress_msg = '#' * progress + '.' * (20 - progress)
msg = f' Processing [{progress_msg}] ({number}/{number_of_pages})'
print(msg, end='\r', flush=True)
# Use
number_of_pages = Page.objects.count()
for number, page in enumerate(Page.objects.all()):
print_status_bar(number, number_of_pages)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment