PyCharm console not printing in the same line, but does in debug console

Answered

I want to show a progress bar in PyCharm, but the console doesn't seem to be printing on the same line. Weird thing is that if I run the code in debug mode, the debug console works properly, printing the progress bar in the same line). Here's the code snippet for the progress bar (source):

import sys
import time

for i in range(10):
    sys.stdout.write("\r{0}".format(str(i)))
    sys.stdout.flush()
    time.sleep(1)

I'd appreciate if you could help me identify what's wrong with the console.

0
3 comments

Hi,

Python Console shows you the same result as if you run "python" in the system terminal and run this code. The debug console shows you the same result as if you run the code with "Emulate terminal in output console" option checked in Run/Debug Configuration.

So you can, for example, disable "Run with Python console" in Run/Debug Configuration and you will have the same result.

0

@Sergey Karpov

Thanks for your prompt reply. When I run the code with "Emulate terminal in output console" option, the progress bar appears to be OK. The only problem with that is I lose the interactive console after running the code. I want to be able to interact with the variables once the code is done running.

On another note,I tried running the script in the system terminal and the progress bar appears to be OK. So, I think there's something else going on here. Any idea what that might be or how I can track it down?

0

>On another note,I tried running the script in the system terminal and the progress bar appears to be OK.

If you run 'python' command first and then copy and paste this code and run it, you will see the same result as in Python Console in PyCharm.

There is no such setting, unfortunately, to make it behave similar to the terminal at this point. Please feel free to submit a feature request about it to our issue tracker using the link https://youtrack.jetbrains.com/issues/PY and let us know if you need any help.

0

Please sign in to leave a comment.