Spyder: Backspace (\b) and carriage return (\r) characters are not printed correctly in the console

Created on 17 Feb 2015  Â·  14Comments  Â·  Source: spyder-ide/spyder

_From [email protected] on 2010-04-10T13:59:33Z_

What steps will reproduce the problem?

1.type: print("Yes\bno") 2. 3. What is the expected output? What do you see instead? expected: yeno
observed: yes[checkmarkcharacter]no What version of the product are you using? On what operating system? 1.1.0beta1

Please provide any additional information below

. seen screenshot

Attachment: spyder_backspace.png

_Original issue: http://code.google.com/p/spyderlib/issues/detail?id=195_

6–10 stars Python Console Bug

Most helpful comment

Don't know if it's helpful for troubleshooting, but I was able to get the desired \r behavior in the Spyder console by using \r in both the object and end arguments for print.

This produces desired overwriting of the output:

import time

for n in range(1, 11):
    print('\r{}'.format(n), end='\r')
    time.sleep(.5)

This incorrectly produces the numbers 1 through 10 each on a new line, without overwriting:

import time

for n in range(1, 11):
    print('\r{}'.format(n))
    time.sleep(.5)

This incorrectly produces the numbers 1 through 10 all on the same line, without overwriting:

import time

for n in range(1, 11):
    print('{}'.format(n), end='\r')
    time.sleep(.5)

All 14 comments

_From [email protected] on 2010-09-15T14:38:19Z_

Tested again on spyder 1.1.6. Using the example I get 'yesno' as output. Backspace is not printed.

_From ccordoba12 on 2011-04-15T07:00:29Z_

I can confirm that this still happens in Spyder 2.0, but now I get "Yes°no"

Summary: Backspace character is printed incorrectly in the console
Status: Accepted
Labels: -Priority-Medium Priority-Low

_From ccordoba12 on 2011-05-15T08:05:07Z_

I've been investigating this issue and it turns out it's not an encoding problem or anything related. To the best of my understanding, to print correctly these characters you have to be working on a proper terminal (bash or cmd.exe) and not inside a GUI.

I've tried to print them on the python interpreters I have at hand (ipython-qtconsole, wing-ide, Eric, IDLE and ipython-notebook) and I can confirm the same problem in all of them. It also occurs in environments not based on Python, for example in Eclipse: https://bugs.eclipse.org/bugs/show_bug.cgi?id=76936 This issue could be solved by emulating the terminal behavior inside Spyder. We could check if the user wants to print a string that contains these characters and preparse the input before sending it to the console, so that the result be the expected.

But for that to happen I would like to hear some good reasons of those who reported the problem, to see if it's really worth the effort to implement this feature.

Summary: Backspace (\b) and carriage return (\r) characters are not printed correctly in the console

_From ccordoba12 on 2011-05-15T08:06:23Z_

issue #645 has been merged into this issue.

_From ccordoba12 on 2011-05-15T19:21:05Z_

Labels: Cat-Console

_From [email protected] on 2012-10-08T08:16:45Z_

Terminal-like support for \b and \r characters provides a simple way to make animations in standard out (using sys.stdout.write() ), such as a progress bar for a download (think wget). In such a use, it is not sufficient to only modify isolated strings that contains these characters, but you also need to remember where the cursor is so that a subsequent call to sys.stdout.write() starts at the intended point.

_From ccordoba12 on 2012-10-08T10:27:39Z_

I think this was fixed for the IPython qtconsole some time ago. I don't think we are going to fix this for our Python console, because it seems to much trouble for what you can get.

But if someone wants to help us with this and send a patch, then we'll be happy to review it and add it to our tree.

_From [email protected] on 2014-02-18T14:29:01Z_

I think its worth the effort.
The scientific use of python often involves running slow code, and without a good progress bar it is hard to know if your code is running (or going to return in finite time).
Could you reconsider?

_From ccordoba12 on 2014-02-19T12:49:26Z_

Please send us a pull request if you consider it important enough or just use one of our IPython consoles (which I know for sure have this functionality implemented).

Status: HelpNeeded

_From ccordoba12 on 2014-12-18T08:45:14Z_

Status: Accepted
Labels: MS-v2.4

_From ccordoba12 on 2014-12-18T09:01:48Z_

This issue was closed by revision ce3d4d0af8a5

Status: Fixed

Hello there, this issue has been closed years ago, but it still exists for me. I was wondering if I should create a new issue, but I give it a try here.
Versions: Spyder 3.3.3 | Python 3.7.1 64-bit | Qt 5.9.6 | PyQt5 5.9.2 | Windows 10

Example code:

import time

for i in range(100):
    print(i, end='\r')  # OK
print()

for i in range(1000):
    print(i, end='\r')  # OK
print()

for i in range(10000):
    print(i, end='\r')  # Fail
print()

for i in range(10):
    time.sleep(0.2)
    print(i, end='\r')  # Fail

Output in external system terminal (expected output):

99
999
9999
9

Output in IPython console in Spyder:

99
999
9999280858079806
9134678

Printing progress information in my loops is important to me, and therefore I cannot use the Spyder console for most of my scripts. Why can't I find more complaints about this? Am I missing something?

Thanks to all contributers for their work & regards!

@jnettels, this was fixed for our (old and now removed) Python console. However, this is still an issue in our IPython console.

The problem was reported alredy in https://github.com/jupyter/qtconsole/issues/272. If you have time, please take a look at qtconsole's code to see if you can help us to fix it (it's low priority for us right now).

Don't know if it's helpful for troubleshooting, but I was able to get the desired \r behavior in the Spyder console by using \r in both the object and end arguments for print.

This produces desired overwriting of the output:

import time

for n in range(1, 11):
    print('\r{}'.format(n), end='\r')
    time.sleep(.5)

This incorrectly produces the numbers 1 through 10 each on a new line, without overwriting:

import time

for n in range(1, 11):
    print('\r{}'.format(n))
    time.sleep(.5)

This incorrectly produces the numbers 1 through 10 all on the same line, without overwriting:

import time

for n in range(1, 11):
    print('{}'.format(n), end='\r')
    time.sleep(.5)
Was this page helpful?
0 / 5 - 0 ratings