I'm somewhat new to programming and Python. I'm actually making a little function which write a sentence letter by letter. Here's the code :
import time
def slowWriting(txt, speed=0.01):
for c in txt:
print(c, end='\r')
time.sleep(speed)
print()
The issue is that when building the function with cxfreeze, and executing the .exe, for the line :
<module_name>.slowWriting("abcd")
Instead of displaying :
abcd
The console displays :
d
In fact, when a character is displayed, he replaces the previous displayed character... How to make it work ?
Thanks for reading and your potential answer.
\r
is carriage return. It returns the cursor to the beginning of the line. That is why you are seeing this behavior. You should use ''
as the end character for print
.