Last active
September 12, 2016 00:10
-
-
Save dusansimic/37e9dd690be5a32d7ddc4f8ed4368871 to your computer and use it in GitHub Desktop.
Spinner in python.
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
import sys | |
import time | |
def spinning_cursor(): | |
while True: | |
for cursor in '|/-\\': | |
yield cursor | |
def start(): | |
spinner = spinning_cursor() | |
while True: # spin forever | |
sys.stdout.write(next(spinner)) # in python3 use this line of code | |
# sys.stdout.write(spinner.next()) in python2 use this line of code | |
sys.stdout.flush() | |
time.sleep(0.1) | |
sys.stdout.write('\b') | |
# function start can be called from any other python script by just importing spinner script |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment