readline() with arbitrary end of lines
François Granger
francois.granger at free.fr
Sun Sep 17 16:02:24 EDT 2000
Javier Bezos <see.below at no.spam.es> wrote:
> I'm using MacPython 1.5.2c1 to read several files with
> the help of readline(). However, the files to be read can
> have either Mac or Unix end of lines and it seems that only
> Mac end of lines are recognized; changing linesep has no
> effect at all.
¡Holà! Javier,
I had the same issue. I had to have Mac end of lines inside the files to
further use the rfc822 lib. I came with this quick and dity hack
temp = f.read()
f.seek(0)
crNum = string.count(temp, '\r')
lfNum = string.count(temp, '\n')
if lfNum == crNum: # dos
f.close()
os.rename(file, join(doneFolder, split(file)[1][:27]) + '.dos')
temp = string.replace(temp, '\n\r', '\n')
f = open(file, 'w')
f.write(temp)
f.close()
f = open(file)
elif crNum:
f.close()
os.rename(file, join(doneFolder, split(file)[1][:27]) + '.uix')
temp = string.replace(temp, '\r', '\n')
f = open(file, 'w')
f.write(temp)
f.close()
f = open(file)
--
"Le sol n'oublie rien, il transmet."
- Danièle
More information about the Python-list
mailing list