Last active
January 23, 2018 02:38
-
-
Save xiazhibin/3126dc6de26acab4e09de81914a41ee4 to your computer and use it in GitHub Desktop.
cmd_loading_bar.py
This file contains 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
#! /usr/bin/env python | |
# -*- coding=utf8 -*- | |
import time | |
now = time.time() | |
word = '....' | |
i = 0 | |
ar = ['-', '\\', '|', '/'] | |
import sys | |
out = sys.stdout | |
for i in range(100): | |
m = word + ar[i % 4] | |
out.write(m) | |
out.flush() | |
out.write('\b' * len(m)) | |
out.flush() | |
i += 1 | |
time.sleep(0.1) | |
################### | |
import time | |
ar = ['.', '..', '...', '....'] | |
import sys | |
last_lenght = 0 | |
out = sys.stdout | |
for i in range(100): | |
out.write('\b' * last_lenght) | |
sys.stdout.write(' ' * last_lenght) | |
sys.stdout.write('\b' * last_lenght) | |
m = ar[i % 4] | |
out.write(m) | |
out.flush() | |
last_lenght = len(m) | |
time.sleep(0.5) | |
########################## | |
import time | |
import sys | |
for i in range(101): | |
sys.stdout.write('\r') | |
sys.stdout.write("%s%% |%s" % (int(i % 101), int(i % 101) * '#')) | |
sys.stdout.flush() | |
time.sleep(0.5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment