I need to print out rotating fan based on this answer with Python.
import threading
import subprocess
I = 0
class RepeatingTimer(threading._Timer):
def run(self):
while True:
self.finished.wait(self.interval)
if self.finished.is_set():
return
else:
self.function(*self.args, **self.kwargs)
def status():
global I
icons = ['|','/','--','\\']
print icons[I]
I += 1
if I == 4: I = 0
timer = RepeatingTimer(1.0, status)
timer.daemon = True # Allows program to exit if only the thread is alive
timer.start()
proc = subprocess.Popen([ 'python', "wait.py" ])
proc.wait()
timer.cancel()
This code works as I can show the fan, but with carriage return to show as follows.
|
/
--
\
|
/
--
...
What's the python code to print the characters without moving the caret position?