Jump to content

print 2 linhas e sobrepor


fabiodurgante

Recommended Posts

ola tenho seguinte 

tamanho = len(lista)

    while True:
                        print(colored(CYAN.format(strftime('%d/%m/%Y'))),colored(CYAN.format(strftime("%H:%M:%S"))),colored(CYAN.format('<-> '))), end="", flush=True) 
                        print("\r", end="", flush=True)

assim escreve data e hora sempre na mesma linha segundo por segundo, quero escrever  ate tamanho da lista depois que atigir tamanho da lista sobrepor o print eemplo

23/11/2020  09:53:20

23/11/2020  09:53:21

agora comecar a sobrerpor  digamos que tamanho da lista seja 2 sobrepor aora imprime 2 vezes e depois sobrepor

23/11/2020  09:53:22

23/11/2020  09:53:23

Link to comment
Share on other sites

Boas,

Basicamente tens de mover o "cursor" para a "primeira" linha.

Se estiveres em Linux é simples, é só uma "escape sequence", se estiveres em Windows, começa a usar linux, isto é, é mais difícil.

Para referência: https://rosettacode.org/wiki/Terminal_control/Cursor_positioning#Python

def move_cursor(x, y):
  print("\033[%d;%dH" % (x,y), end="", flush=True)

Força aí

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.