Skip to content

Latest commit

 

History

History
35 lines (31 loc) · 1.38 KB

progress-bar.md

File metadata and controls

35 lines (31 loc) · 1.38 KB

라이브러리 없이 progress bar 만들기

  • 라이브러리 없이 아래와 같이 구현할 수 있다
# Print iterations progress
def printProgressBar (iteration, total, prefix = '', suffix = '', decimals = 1, length = 100, fill = '█', printEnd = "\r"):
    """
    Call in a loop to create terminal progress bar
    @params:
        iteration   - Required  : current iteration (Int)
        total       - Required  : total iterations (Int)
        prefix      - Optional  : prefix string (Str)
        suffix      - Optional  : suffix string (Str)
        decimals    - Optional  : positive number of decimals in percent complete (Int)
        length      - Optional  : character length of bar (Int)
        fill        - Optional  : bar fill character (Str)
        printEnd    - Optional  : end character (e.g. "\r", "\r\n") (Str)
    """
    percent = ("{0:." + str(decimals) + "f}").format(100 * (iteration / float(total)))
    filledLength = int(length * iteration // total)
    bar = fill * filledLength + '-' * (length - filledLength)
    print(f'\r{prefix} |{bar}| {percent}% {suffix}', end = printEnd)
    # Print New Line on Complete
    if iteration == total: 
        print()
  • 아래와 같이 사용할 수 있다
items = list(range(0, 100))
for idx, item in enumerate(items):
 printProgressBar(i + 1, l, prefix = 'Progress:', suffix = 'Complete', length = 50)