how to rewrite output in terminal,sys.stdout.flush()