I have a Python program that makes extensive use of the line character to create the effect of an update console line (in particular, a progress bar).
When trying to debug code in PyCharm, I saw that the progress bar does not print until it finishes.
Upon further inspection, it turned out that when the carriage return returns ( \r ), the entire line is deleted.
Since the library itself writes form lines ( {line}\r ), I always get an empty line.
Is there a way to solve this problem using PyCharm? Currently, what I will do is replace stdout version that writes the current line and retypes it after receiving a carriage return. However, I would have a pretty simple way to do this.
Code example:
import sys sys.stdout.write('xxx') sys.stdout.flush() time.sleep(1) sys.stdout.write('\rZZ') sys.stdout.flush() time.sleep(1) sys.stdout.write('yyy\r') sys.stdout.flush() time.sleep(1) print ('===')
My launch looks like this:
1. "xxx" is printed
[After 1 second]
2. "ZZ" is printed
[After 1 second]
3. Line deleted
[After 1 second]
4. '===' is printed and the program terminates
This happens both in the debug console and in the launch console when the script is run.
python carriage-return pycharm console-application
Tomm
source share