I found strange thing while studying through idle
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Thu Mar 8 22:57:53 EST 2018
I'm afraid the original post by 노연수<clear0755 at naver.com> has not come
through to me, so I will have to reply to Ben's reply.
On Fri, 09 Mar 2018 12:59:52 +1100, Ben Finney wrote:
> I am not using Python 3.7 (it isn't released yet); I recommend staying
> with the latest Python release. Today, that is version 3.6.
3.6 is the latest *stable* release; but there are unstable releases, such
as 3.7.0.b2.
We should be glad that there are people willing to run unstable and beta
versions, otherwise they would not get any real-world testing, bugs would
not be fixed, and the "stable" X.Y.0 release would be a de-facto
unstable, untried beta version.
> When I use Python 3.6 and run the code example you give, it behaves this
> way::
>
> >>> print (" hello\ rpython ")
> hello\ rpython
My guess is that the Original Poster carelessly re-typed his code instead
of copying and pasting it. When he said he tried this:
print (" hello\ rpython ")
what he *actually* did was probably something like this:
print ("hello\rpython")
When I try that, I get this:
py> print ("hello \rpython")
python
which seems to match the OP's description.
Printing strings containing \r (carriage returns) may be dependent on the
console or terminal you use, and even on *where* the carriage return is
in the string, but in general I expect that printing \r will instruct the
terminal to return to the beginning of the CURRENT line. The rest of the
string will then overwrite the beginning of the line. For example:
py> print ("hello world\rpython")
pythonworld
>> However, if you type print (" hello\ rpython ") in the python 3.7.0.b2
>> idle, it is output as hellopython.
Again, my prediction is that the OP has carelessly retyped his code, and
what he means is
print ("hello \rpython")
which in IDLE *does not* return to the start of the line.
In IDLE 3.5 on Linux, I get this:
>>> print('hello\rpython')
hello\rpython
Curiously, that's not a backslash r, it's actually a carriage return:
when I copy and paste it in this text, the editor treated it as a new
line character:
# direct copy and paste becomes this in my editor
>>> print('hello\rpython')
hello
python
But it is possible that due to differences between platforms, the OP's
version of IDLE doesn't display a carriage return as \r but rather as an
invisible zero-width space.
--
Steve
More information about the Python-list
mailing list