Created
December 25, 2020 04:21
-
-
Save shiracamus/b7b1baf828bd0345f28d3945bda4a032 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
def sec_to_time(sec): | |
"""引数secの秒数を'HH:MM:SS'形式文字列に変換して返す""" | |
m, s = divmod(int(sec), 60) | |
h, m = divmod(m, 60) | |
return f'{h:02}h {m:02}m {s:02}s' | |
def progress(items): | |
last = len(items) | |
start = time.time() | |
for count, item in enumerate(items, 1): | |
yield item | |
end = time.time() | |
average = (end - start) / count | |
remain = (last - count) * average | |
print(f'\r{count}/{last}, 残り時間見込み:{sec_to_time(remain)}', end='') | |
print() | |
def main(): | |
a = 0 | |
for num in progress(range(10000)): | |
a += num | |
time.sleep(0.1) | |
print(a) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment