The print()
function will print all characters in your message, then append the end character after printing. If you omit end=
it defaults to a newline character (\n
on nix). The \r
character moves the cursor to the beginning of the same line.
So lets look at a few situations in the python interpreter:
# print 'text' followed by \r (move to beginning of line) followed by newline
>>> print('text\r')
asdf
>>>
In this example, text
is printed, the cursor then moves to the beginning of the same line, then the default newline character is printed moving to the next line. Finally, python prints its prompt.
# print 'text' followed by \r followed by nothing
>>> print('text', end='\r')
>>>
In this example, text
is printed, the cursor moves to the beginning of the same line, then the command is finished and the interpreter prints its prompt >>>
overwriting the text
that was printed.
# print 'text followed by \r followed by nothing (alternate)
>>> print ('text\r', end='')
>>>
The above is identical to the previous example.
The situation is very similar when you run your script using python from the terminal, except instead of the python interpreter printing its prompt, your shell is printing its prompt after the program executes.
It's difficult to suggest a "fix" here because it's unclear what you actually want to accomplish.