0

The environment is Python 3.6 and win10 x64. I wanted to output the string '123456\rabc' by using print(), the right result should be 'abc456', but I got different answers.

1. IPython:

    Python 3.6.1 |Anaconda 4.4.0 (64-bit)| (default, May 11 2017, 13:25:24) [MSC v.1900 64 bit (AMD64)]
    Type "copyright", "credits" or "license" for more information.

    IPython 5.3.0 -- An enhanced Interactive Python.
    ?         -> Introduction and overview of IPython's features.
    %quickref -> Quick reference.
    help      -> Python's own help system.
    object?   -> Details about 'object', use 'object??' for extra details.

    In [1]: print('123456\rabc')
    abc456

    In [2]:

2. python.exe

    Python 3.6.1 |Anaconda 4.4.0 (64-bit)| (default, May 11 2017, 13:25:24) [MSC v.1900 64 bit (AMD64)] on win32
    Type "help", "copyright", "credits" or "license" for more information.
    >>> print('123456\rabc')
    abc456
    >>>

3. Sublime Text3

    print('123456\rabc')

I run the file test.py, and the result was this:

    123456
    abc
    [Finished in 0.1s]

4. PyCharm 2017.2.3 x64

I still run test.py, the result was:

    C:\Users\user\Anaconda3\python.exe C:/Users/user/Desktop/cv/test.py
abc

    Process finished with exit code 0

So I don't know why these results are different.

piet.t
  • 11,718
  • 21
  • 43
  • 52
  • 2
    I think you should first check if all programs emit the same byte sequence. For example by piping it to a hex dump utility. If yes, the problem most probably is that each terminal-like device interprets the CR control character differently. – VPfB Oct 12 '17 at 07:04
  • Try this post : https://stackoverflow.com/questions/34751441/when-writing-carriage-return-to-a-pycharm-console-the-whole-line-is-deleted – Aaditya Ura Oct 12 '17 at 08:26
  • Thanks for your advance. Just as what you said,it may because of the different devices. – Noah Feng Oct 12 '17 at 08:30
  • I find this post: https://stackoverflow.com/questions/26575014/python-carriage-return-not-working – Noah Feng Oct 12 '17 at 09:18

0 Answers0