Skip to content

Instantly share code, notes, and snippets.

@dusansimic
Last active September 12, 2016 00:10
Show Gist options
  • Save dusansimic/37e9dd690be5a32d7ddc4f8ed4368871 to your computer and use it in GitHub Desktop.
Save dusansimic/37e9dd690be5a32d7ddc4f8ed4368871 to your computer and use it in GitHub Desktop.
Spinner in python.
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