Skip to content

Instantly share code, notes, and snippets.

@xiazhibin
Last active January 23, 2018 02:38
Show Gist options
  • Save xiazhibin/3126dc6de26acab4e09de81914a41ee4 to your computer and use it in GitHub Desktop.
Save xiazhibin/3126dc6de26acab4e09de81914a41ee4 to your computer and use it in GitHub Desktop.
cmd_loading_bar.py
#! /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