[Tutor] Printing the Carriage return character

Hans Dushanthakumar Hans.Dushanthakumar at navman.com
Mon Feb 20 21:32:17 CET 2006

Thanks Alan for clearing that up...I was trying to see why my "\r\n"
does not print 2 empty lines when I stumbled across this 'gotcha'. 

-----Original Message-----
From: Alan Gauld [mailto:alan.gauld at freenet.co.uk] 
Sent: Monday, 20 February 2006 9:22 p.m.
To: Hans Dushanthakumar; tutor at python.org
Subject: Re: [Tutor] Printing the Carriage return character

>    Not sure if this is a python thing or a Operating system 
> peculiarity,

An IDLE thing specifically - or maybe even  a Tkinter thing...

> Why does the line
> print "FirstLine" + "\rSecondLine"
> produce different output when run via IDLE and when run in the python 
> prompt (both under Windows XP)?

\r is a carriage return which literally means that the printhead
carriage should return to the start of the line. You need a line feed
character if you want a new line too.

Unfortunately some OS use \r to do both, others need both.
The safe way is to use \n (new line) instead.

> Output in IDLE (ver 1.1.1, python 2.4.1):
> FirstLine
> SecondLine

> Output at the python prompt (python 2.4.1):
> SecondLine

So being pedantic XP is correct, IDLE is wrong but in fact because the
conventions are so mixed up right and wrong is a bit woolly.

Which response were you trying to get?

Alan G
Author of the learn to program web tutor

More information about the Tutor mailing list