Created
May 7, 2021 03:07
-
-
Save askrabal/bc1c9be5d54359202759992040d5be45 to your computer and use it in GitHub Desktop.
Simple python script that shows how to continuously print on 2 lines
This file contains hidden or 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
#!/usr/bin/env python3 | |
from sys import argv, stdout | |
from time import sleep | |
import random | |
random.seed() | |
end = 10 | |
rest = 1.0 | |
if len(argv) > 1: | |
end = int(argv[1]) | |
if len(argv) > 2: | |
rest = float(argv[2]) | |
def rprint(raw: str, file_name=stdout): | |
file_name.write(raw) | |
def reprint_lines(num_lines: int): | |
for i in range(num_lines): | |
rprint("\033[1A") # go up 1 line | |
rprint("\033[2K") # clear line | |
rprint("\033[G") # move to begin of line | |
for ii in range(1, end + 1): | |
num = random.randint(0, 99999) | |
print(f"Show me {end} random numbers:") | |
print(f"{num:5}") | |
sleep(rest) | |
if ii < end: | |
reprint_lines(2) | |
else: | |
pass | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment