PyCharm output end = '\ r' does not work

There are already many other questions about the print statement, but I did not find the answer to my problem:

When I do this:

for idx in range(10): print(idx, end="\r") 

on the (ipython) terminal directly, it works great and always overwrites the previous line. However, when running in a module with PyCharm, I do not see any lines printed in stdout.

Is this a known PyCharm issue?

+5
source share
2 answers

Try:

  for idx in range(10): print('\r', idx, end='') 

Carriage return front and end '' to avoid a new line \ n '. One way to avoid using space is to use a format convention:

  for idx in range(10): print("'\r{0}".format(idx), end='') 
+3
source

I had the same problem. Although the solution using print () eluded me, I found that sys.stdout.write works fine. (Win10, Python 3.5.1, Pycharm 2016.3.2)

 import sys import time def countdown(n): for x in reversed(range(n)): sys.stdout.write('\r' + str(x)) time.sleep(1) countdown(60) 
+1
source

Source: https://habr.com/ru/post/1241253/


All Articles