[Tutor] end of file symbol?

Kent Johnson kent_johnson at skillsoft.com
Mon Nov 1 22:35:21 CET 2004


Jeff,

end-of-line is platform-dependent. On Unix / Linux / Mac OSX it is \n. On 
Windows it is usually \r\n. On MacOS 9 it is \r.

If you open a file with the mode 'U' or 'rU' you get "universal newline 
support" which converts any of these newline types to \n. (See 
http://docs.python.org/whatsnew/node7.html)

If you are processing text line-by-line, there might be a better way to do 
it than searching for \n. You can read a file by lines like this:
f = open('myfile.txt', 'rU')
for line in f:
     # do something with line

If you have the text in a string already you can use
for line in s.splitlines():
     # do something with line

or just
lines = s.splitlines()
to get a list of all the lines.


There is no end-of-file character, you just run out of data.

Kent

At 01:14 PM 11/1/2004 -0800, Jeff Peery wrote:
>is there an end of file symbol? or an end of line symbol? usually I look 
>for '\n' when I am filtering though text to find the end of a line, but I 
>am wondering if there is a better end of line character. thanks.
>
>Jeff
>_______________________________________________
>Tutor maillist  -  Tutor at python.org
>http://mail.python.org/mailman/listinfo/tutor



More information about the Tutor mailing list