[Tutor] checking if data files are good, readable, and exist
bgailer at gmail.com
Wed Jul 23 01:47:30 CEST 2008
Alan Gauld wrote:
> But that isn't. Python just reads the data and interprets it
> as text if you specify a text file - the default - or as raw data
> if you use rb.
But it DOES handle line-ends in an OS independent manner. Windows uses
CR-LF as a line end, whereas Unix, Linux, Mac use (just CR or is it LF?).
Python presents line-ends uniformly as \n when you open the file in text
Witness: (on Windows)
>>> f = open('c:/foo.txt', 'r')
'this line contains as\nbut this has as\n'
>>> f = open('c:/foo.txt', 'rb')
'this line contains as\r\nbut this has as\r\n'
919-636-4239 Chapel Hill, NC
More information about the Tutor