Readline and record separator

Bruno Desthuilliers bdesth.quelquechose at free.quelquepart.fr
Tue Oct 30 20:44:48 CET 2007


Johny a écrit :
> Is it possible to change record separator when using readline?
> As far as I know readline reads characters until found '\n' and it is
> the end of record for readline.

This is not a "record" separator, but a newline. As the name implies, 
file.readline is about reading a text file line by line. For a 
definition of "line" being : "a chuk of text that starts either at the 
beginning of the document or after a newline" and for a definition of 
"newline" being "a platform-specific character or character sequence".

> My problem is that my record consits several '\n' and when I use
> readline it does NOT read the whole my record.
> So If I could change '\n' as  a record separator for readline, it
> would solve my problem.
> Any idea?

If you're dealing with (so-called) CSV files, you might want to have a 
look at the (oh surprise) CSV module (in the stdlib) instead.

HTH



More information about the Python-list mailing list