Pycharm won't flush after print in long for-loop

Viewed 36

When I run this simple program in a terminal, it prints the count number fine every 10,000 steps:

import sys
from numpy import mod

for i in range(2000000):
    if mod(i, 10000) == 0:
        print(i, end='\r')

When I run it in Pycharm (Community 2021.3.2), I get one number after the loop is finished, or sometimes no number.

Even when I add these three flush options, it doesn't help. How do I force Pycharm to flush?

print = functools.partial(print, flush=True)

for i in range(2000000):
    if mod(i, 10000) == 0:
        print(i, end='\r', flush=True)
        sys.stdout.flush()
0 Answers
Related