1
print "-------------------\r"

produces a musical note instead doing the carriage return. Why?

Thanks in advance for reply.

EDIT: I was using it in this code in order to change dinamically data by 'print' instead to re-print it all:

import math
import time

    while True:
        reading = read_world_2c(0x43) #it's a function for reading data from a sensor
        print "data:     \r", reading
        time.sleep(0.5) 
cyberdyne
  • 426
  • 3
  • 5
  • 23

1 Answers1

3

That musical note is the symbol for line breaks. If you have MS Word or Notepad++ or similar, open or type some text and then find the menu command for "show nonprinting characters ". You will see those "musical notes" at the end of each line.

Crowcoder
  • 11,250
  • 3
  • 36
  • 45
  • Is there a way to replace 'break' with the carriage return \r for 'print' in Python? – cyberdyne Sep 24 '14 at 10:35
  • I don't think there is a problem with your code but I'm not a Python programmer. Try \n or os.linesep : http://stackoverflow.com/questions/454725/python-get-proper-line-ending – Crowcoder Sep 24 '14 at 10:58
  • the only '\n' works. I have used os.linesep in the shell and it returns only '\n'. I have read that it would return '\r\n'. – cyberdyne Sep 24 '14 at 11:12
  • 1
    @Orlok [This Stackoverflow question](http://stackoverflow.com/questions/15433188/r-n-r-n-what-is-the-difference-between-them) can tell you more about \r, \n, and \r\n. – MackM Sep 26 '14 at 16:19
  • I do not see any char. The IDLE doc, Help ==> IDLE Help, section User output in Shell discusses the printing of control characters. Result depends on OS and font, and possibly tcl/tk version. – Terry Jan Reedy Jun 11 '19 at 02:10