1

idle prints \r as ♪

Code

print('haha', end='\r')

print('haha\rhehe')

This is output

haha♪

haha♪hehe
#

Thanks for finding another same question! Is there any possible way to use \r? There is no explain about this...

Sparkling
  • 21
  • 3
  • 5
    I don't get this behavour, which python version are you using? – Devesh Kumar Singh Jun 10 '19 at 11:44
  • 3
    Possible duplicate of [In python carriage return \r returns a musical note](https://stackoverflow.com/questions/26014341/in-python-carriage-return-r-returns-a-musical-note) – John Coleman Jun 10 '19 at 11:57
  • It isn't as weird as it seems at first. I am old enough to have learned typing on mechanical typewriters and still remember the melodic bell that rang when you had a carriage return (though the link between carriage returns and bells was somewhat indirect). In any event, why not just use `'\n'`? – John Coleman Jun 10 '19 at 12:06
  • I use python 3.7.3 and I need to move to the left and overwrite so I've to use \r... – Sparkling Jun 10 '19 at 12:20
  • What is the exact output you want? We can come up with an alt – Joshua Nixon Jun 10 '19 at 12:50
  • I've to combine two strings! ex) " 1\n1 " and "1 \n 1" – Sparkling Jun 10 '19 at 13:18

1 Answers1

0

By default, python (not IDLE) sents print output to sys.stdout. IDLE connects sys.stdout to a tinter (tcl/tk) Text widget. What happens then depends on tk, the operating system, and the font you are using. For control characters other than tab ('\t') and enter ('\n'), the result is undefined. Possibilites include nothing, a space, and a puzzling symbol character. With 3.7.3 on Win 10 with SourceCodePro font, I see nothing. print('a\rb') results in ab. The IDLE doc, Help ==> IDLE Help, section User output in Shell discusses the printing of control characters.

To see what would happen if you run your code directly with python in a particular terminal or console, run it in that particular environment. To control output in detail regardless of OS, use a gui framework such as tkinter.

Terry Jan Reedy
  • 18,414
  • 3
  • 40
  • 52