Search code examples
pythonshellpython-3.xconsole

Print over Current Line in Python Shell


I'm trying to make a percentage text that displays a progress amount but i'm trying to avoid the percentages printing out like this:

Progress: 10% Progress: 11% Progress: 12% Progress: 13%

How can erase and write over the current line? Iv'e tried using the \r and \b characters but neither seems to work. Every single thing I found before has been for either for Python 2 or Unix so i'm not even sure which of those is the problem (if even one of them) because i'm not using either. Does anyone know how I can do this with Python 3 running Windows 7? This is the unworking code that I have currently, but I've tried plenty of other things.

print('Progress: {}%'.format(solutions//possibleSolutions),flush=True,end="\r")

EDIT:

This is not a problem if I'm executing the program from command prompt so I don't think it is a problem with windows. I tried updating Python from what i was using previously (3.4.1) to the latest v3.4.3 and the issue is the same.

Heres a screenshot of the problem: This is the best I can do at taking a screenshot of the issue. It appears as if each time I move the cursor farther to the left (passed one of the Progress:'s) that the gray area between the text and the cursor gets larger

EDIT 2: The problem is that IDLE does not support ASCII control codes. Solution: Use a different IDE.


Solution

  • You can use print:

    print('Progress: {}%'.format(solutions),flush=True,end="\r")