Context
I have difficulties finding the right stackoverflow question for this purpose:
I would like to update a printed line in python with a value that is computed after something else is printed. the something else
should stay below the line that is updated.
For example:
first="hello"
third=""
print(f'{first} \r{third}', end=" ", flush=True)
second="somethingelse"
print(second)
if second == "somethingelse":
third="world"
else:
third="Universe"
Should print:
hello
something.
which is then changed to:
hello world
something
Or it should print:
hello
something.
which is then changed to:
hello universe
something
It is important that:
- hello is printed before something is printed.
- world/universe is printed on the same line as hello.
- something is below the hello universe/world line.
- something can consist of an arbitrary number of printed lines.
XY-problem
I modified the showme pip package to show the runtimes of functions. And I would like the function name to be printed, followed by the output of the function that is being running. And still print the runtime behind/on the same line as the function name. (To reduce the CLI clutter).
Question
How do I update a line with a value that is computed after other stuff is printed below that line?
Related Questions:
How can I print something, and then call a function with a print on the same line?