xeus-python icon indicating copy to clipboard operation
xeus-python copied to clipboard

String formatting inconsistency with Python 3 (Possible bug?)

Open jerrykaplan opened this issue 4 years ago • 0 comments

I'm using Jupyterlab with kernel Python 3.9 (XPython) on an M1 Mac Air. The following code does not overwrite the line as expected:

for d in range(10):
    for g in range(1000):
        if not (g % 50): print("\rd=",d,"g=",g, end=" ")

The output looks like this:

d= 0 g= 0 0 g= 50 0 g= 100 0 g= 150 0 g= 200 0 g= 250 0 g= 300 0 g= 350 0 g= 400 0 g= 450 0 g= 500 0 g= 550 0 g= 600 ... 8 g= 950 9 g= 0 9 g= 50 9 g= 100 9 g= 150 9 g= 200 9 g= 250 9 g= 300 9 g= 350 9 g= 400 9 g= 450 9 g= 500 9 g= 550 9 g= 600 9 g= 650 9 g= 700 9 g= 750 9 g= 800 9 g= 850 9 g= 900 9 g= 950

(My ellipsis.)

Using the Python 3 kernel, I get the expected output (overwritten the "final" time):

d= 9 g= 950

This isn't an output buffer timing issue - adding a time.sleep(1) inside the loop doesn't change the results, nor does adding "flush=True".

jerrykaplan avatar Apr 30 '21 04:04 jerrykaplan