Skip to content

Instantly share code, notes, and snippets.

@juancarlospaco
Last active April 6, 2018 19:36
Show Gist options
  • Save juancarlospaco/4cf777ca29a577eaabb9 to your computer and use it in GitHub Desktop.
Save juancarlospaco/4cf777ca29a577eaabb9 to your computer and use it in GitHub Desktop.
Python ProgressBar OneLiner with 80Chars limit and 0-100 integer range.
progressbar = lambda i: sys.stdout.write("[{}] {}%\r".format(
'#' * (70 * i // 100) + '.' * (70 - 70 * i // 100), 100 * i // 100)[:80])
progress = lambda i: None if i % 2 else sys.stdout.write("[{}] {}%\r".format(
'#' * (70 * i // 100) + '.' * (70 - 70 * i // 100), 100 * i // 100)[:80])
@juancarlospaco
Copy link
Author

>>> progress = lambda i: None if i % 2 else sys.stdout.write("[{}] {}%\r".format(
...     '#' * (70 * i / 100) + '.' * (70 - 70 * i / 100), 100 * i / 100)[:80])
>>> 
>>> 
>>> for i in range(100): 
...     progress(i)   
... 
[......................................................................] 0%
[#.....................................................................] 2%
[##....................................................................] 4%
[####..................................................................] 6%
[#####.................................................................] 8%
[#######...............................................................] 10%
[########..............................................................] 12%
[#########.............................................................] 14%
[###########...........................................................] 16%
[############..........................................................] 18%
[##############........................................................] 20%
[###############.......................................................] 22%
[################......................................................] 24%
[##################....................................................] 26%
[###################...................................................] 28%
[#####################.................................................] 30%
[######################................................................] 32%
[#######################...............................................] 34%
[#########################.............................................] 36%
[##########################............................................] 38%
[############################..........................................] 40%
[#############################.........................................] 42%
[##############################........................................] 44%
[################################......................................] 46%
[#################################.....................................] 48%
[###################################...................................] 50%
[####################################..................................] 52%
[#####################################.................................] 54%
[#######################################...............................] 56%
[########################################..............................] 58%
[##########################################............................] 60%
[###########################################...........................] 62%
[############################################..........................] 64%
[##############################################........................] 66%
[###############################################.......................] 68%
[#################################################.....................] 70%
[##################################################....................] 72%
[###################################################...................] 74%
[#####################################################.................] 76%
[######################################################................] 78%
[########################################################..............] 80%
[#########################################################.............] 82%
[##########################################################............] 84%
[############################################################..........] 86%
[#############################################################.........] 88%
[###############################################################.......] 90%
[################################################################......] 92%
[#################################################################.....] 94%
[###################################################################...] 96%
[####################################################################..] 98%

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment