[Tutor] Escape codes and 'return statements'

Michael P. Reilly arcege@shore.net
Fri, 11 Aug 2000 12:04:08 -0400 (EDT)


>     I'm currently learning Python and I came across this things called =
> "escape codes". I understand fairly most of them except for the escape =
> codes ' \n ' and (linefeed???) and ' \r ' (carriage return).

A little history.  Way back when.. you had typewriters that had two
seperate operations: carriage return, which moved the roller (called
the carriage) back to the beginning of the line; line feed, which moved
the roller up one line.  There was a handle on the carriage that
performed both.

Many computer systems evolved with teletypes (a combination of a
terminal and a typewriter), card readers and paper-tape punchers, all
with similar needs: a carriage return and a line-feed.  So most
computer systems handle those two systems.

Different software vendors developed software to handle EOLN
(end-of-line) to mean either "carriage return", "line feed" or
"carriage-return/linefeed".  The '\r' is the carriage return ASCII
character and '\n' is the line-feed character.  Windows uses the two
combined, UNIX uses '\n' and Macintosh uses '\r'.

Most of the time you will not have to worry about it; in Python, the os
module has a "linesep" constant which changes for each system, as I
described above.  The only real time you have to worry is when you deal
with multiple platforms and have to convert binary data (the "b" mode
in the Python open() function).

  -Arcege

-- 
------------------------------------------------------------------------
| Michael P. Reilly, Release Manager  | Email: arcege@shore.net        |
| Salem, Mass. USA  01970             |                                |
------------------------------------------------------------------------