From: Jeff W. <js...@fa...> - 2009-01-29 18:38:46
|
Christopher Barker wrote: > Jeff Whitaker wrote: > >> John: 'rU' apparently doesn't work for gzipped text files (at least >> in python 2.5.2). I had to change the default in back to 'r' when >> using gzip.open (r6846 in trunk). > > darn -- sounds like a bug/missing feature in the gzip module. Strange > , though, unknown flags seem to be ignored by file(), and gzip.open > seems to ignore the 'U' too, in my tests (see below). > > I think having the 'U' ignored is less than optimal, but doesn't make > anything worse than it is. What problems did you have? Chris: If you have basemap, try running the simpletest.py example with matplotlib svn r6845. When the filehandle is obtained using 'rU', it's reading garbage from the gzipped file. Using 'r', it's fine. -Jeff > > tests (on an OS-X system - native unix newlines): > (python 2.5.2) > > >>> file('test_newlines.txt', 'rb').read() > 'line 1: unix \nline 2: dos \r\nline 3: mac \rline 4: unix \n' > >>> file('test_newlines.txt', 'r').read() > 'line 1: unix \nline 2: dos \r\nline 3: mac \rline 4: unix \n' > >>> file('test_newlines.txt', 'U').read() > 'line 1: unix \nline 2: dos \nline 3: mac \nline 4: unix \n' > > # so file() does the right thing > > >>> gzip.open('test_newlines.txt.gz', 'rb').read() > 'line 1: unix \nline 2: dos \r\nline 3: mac \rline 4: unix \n' > >>> gzip.open('test_newlines.txt.gz', 'r').read() > 'line 1: unix \nline 2: dos \r\nline 3: mac \rline 4: unix \n' > >>> gzip.open('test_newlines.txt.gz', 'rU').read() > 'line 1: unix \nline 2: dos \r\nline 3: mac \rline 4: unix \n' > > > # gzip.open() appears to ignore the 'U' flag -- too bad! > > should we post a bug report/feature request to Python? > > -Chris > > > > -- Jeffrey S. Whitaker Phone : (303)497-6313 Meteorologist FAX : (303)497-6449 NOAA/OAR/PSD R/PSD1 Email : Jef...@no... 325 Broadway Office : Skaggs Research Cntr 1D-113 Boulder, CO, USA 80303-3328 Web : http://tinyurl.com/5telg |