This recipe has a similar objective to http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/473899, but was not derived from it. This recipe was written before the aforementioned recipe was submitted to this Cookbook. The purpose of this demo is to illustrate showing the status of an operation to a user in an ASCII environment.
1 2 3 4 5 6 7 8 9 10 11 12 | import os, time
def main():
status, key = 0, ['|', '/', '-', '\\']
while True:
os.system('cls')
print '.' * (status / 8) + key[status % 4]
status += 1
time.sleep(0.1)
if __name__ == '__main__':
main()
|
This recipe can easily be modified to run Linux (as it is meant to run on Windows) and can even be modified to run on either Windows or Linux (as one program). The main feature of this recipe is its approach to clearing the screen. Finally, "main" can be run in a thread while another thread is actually doing some work. This is demonstrated in http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/473881 through function "__working".
Improvement. I'd prefere to get rid of that os.system call by doing
Themes.