-
-
Save LeoHuckvale/8473f32a47b2a91e8e8d to your computer and use it in GitHub Desktop.
Rotating Stick Class for 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 threading | |
import time | |
class cSpinner(threading.Thread): | |
""" | |
Print things to one line dynamically | |
""" | |
chars = ["\\","|","/","-"] | |
index = 0 | |
keeprunning = True | |
def run(self): | |
while self.keeprunning: | |
self.printing(self.chars[self.index%len(self.chars)]) | |
time.sleep(0.1) | |
self.index +=1 | |
def printing(self,data): | |
sys.stdout.write("\r\x1b[K"+data.__str__()) | |
sys.stdout.flush() | |
def stop(self): | |
self.keeprunning = False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment