Skip to content

Instantly share code, notes, and snippets.

@pfreixes
Last active January 18, 2016 18:45
Show Gist options
  • Save pfreixes/a911dd6e17aca6bcc6a2 to your computer and use it in GitHub Desktop.
Save pfreixes/a911dd6e17aca6bcc6a2 to your computer and use it in GitHub Desktop.
Animations with Python and terminal output
# More info about ANSI escape sequences
# http://ascii-table.com/ansi-escape-sequences.php
import sys
import random
from time import sleep
ROWS = 10
while True:
for i in range(0, ROWS):
sys.stdout.write("*"*random.randint(1, 10) + "\n")
sys.stdout.flush()
sleep(1)
for i in range(0, ROWS):
sys.stdout.write("\033[K") # remove line
sys.stdout.write("\033[1A") # up the cursor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment