M
M
Maxim2020-05-19 11:24:50
Python
Maxim, 2020-05-19 11:24:50

How to change console output?

For example, there is such a program:

import time
print("Hello, World!")
time.sleep(1)
...

What do I need to write in place of ... so that after the output "Hello, World!", after a second it changes to "Hello, User!"?
It was the already displayed line that changed, and not a new one was displayed.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander, 2020-05-19
@XTerris

# -*- coding: utf-8 -*-
import time
import sys


def update_msg(text):
    message = f'\r{text}'
    sys.stdout.write(message)
    sys.stdout.flush()


words = ['world', 'XTerris', 'Maksim']

for word in words:
    update_msg(f'Hello, {word}')
    time.sleep(1)

Z
zexer, 2020-05-19
@zexer

How to change only one part of a string?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question