Python Forum

Full Version: super newbie question: escape character
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
i'm trying pycharm and idle at the same time, and found a strange situation
print("1 hello")
print("2 hell\n o")
[color=#E74C3C]print("3 hell\r xxx")
print("4 hell\rxxx")
print("5 hell\b o")[/color]
print("6 hell\to")
the result
in pycharm:
Output:
1 hello 2 hell o xxx xxx 5 hel o 6 hell o
in idle:
Output:
1 hello 2 hell o 3 hell xxx 4 hell xxx 5 hell o 6 hell o
why are the difference in line 3, 4 & 5? Huh Huh Huh
You have different terminal emulators that are probably dealing with the carriage return character \r differently. The program is sending the same characters to stdout, but the terminal rendering is acting on that information in a different way.

The first is treating it as "go back to beginning of the line". So in that case the text afterward overwrites the text written earlier on that line.

The second is treating it as a more normal end of line and not allowing it to overwrite the previous text.

This looks like a program rendering issue, not a python programming issue. You'd have the same thing if you just had a file with that output as contents and had the programs try to display it.
well, this is all the code, it's something like my third day in Python world
i'm starting from the very beginning.
(Jan-13-2021, 01:08 AM)bowlofred Wrote: [ -> ]You have different terminal emulators that are probably dealing with the carriage return character \r differently. The program is sending the same characters to stdout, but the terminal rendering is acting on that information in a different way.

The first is treating it as "go back to beginning of the line". So in that case the text afterward overwrites the text written earlier on that line.

The second is treating it as a more normal end of line and not allowing it to overwrite the previous text.

This looks like a program rendering issue, not a python programming issue. You'd have the same thing if you just had a file with that output as contents and had the programs try to display it.

i'm reviewing different on-line videos for starters, and one is using the built-in IDLE, the other PyCharm.
Thanks for the tips, as long as it's not a syntax problem, i'm ok. will worry about the setup later.
Danks