분석 Python/구현 및 자료
[ Python ] Loop ProgressBar 구현물
데이터분석뉴비
2019. 10. 23. 17:33
728x90
Python에서 Loop를 돌릴 때 유용한 ProgressBar 구현체
여기다가 먼가 중간 값으로 보고 싶을 때 함수에 추가하면 Loop마다 쌓여서 보이지 않고 그대로 보여줌.
def printProgress(iteration, total, prefix = '', suffix = '', decimals = 1, barLength = 50):
formatStr = "{0:." + str(decimals) + "f}"
percent = formatStr.format(100 * (iteration / float(total)))
filledLength = int(round(barLength * iteration / float(total)))
bar = '#' * filledLength + '-' * (barLength - filledLength)
sys.stdout.write('\r%s |%s| %s%s %s' % (prefix, bar, percent, '%', suffix)),
if iteration == total:
sys.stdout.write('\n')
sys.stdout.flush()
for epoch in epochs :
printProgress(epoch , epochs)
대신에 printProgress에 이후에 특정한 것을 보고 싶어서 다시 Print를 하게 되면 작동 안함!
728x90