[Python-bugs-list] [ python-Bugs-563491 ] Add separator argument to readline()

noreply@sourceforge.net noreply@sourceforge.net
Sun, 02 Jun 2002 06:01:52 -0700


Bugs item #563491, was opened at 2002-06-02 10:04
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=563491&group_id=5470

Category: Python Library
Group: None
>Status: Closed
>Resolution: Rejected
Priority: 5
Submitted By: Ben Escoto (bescoto)
Assigned to: Nobody/Anonymous (nobody)
Summary: Add separator argument to readline()

Initial Comment:
This has probably been suggested previously because it
is so simple, but how about adding a second optional
argument to readline()?  If present, the second
argument would be a string (or possibly just a single
character) that marks the end of each line.  The
default is obviously '\n'. 

This scheme seems natural enough to me, and would
really help when parsing files with null terminated
lines.  There must be a lot of other uses too.



----------------------------------------------------------------------

>Comment By: Martin v. Löwis (loewis)
Date: 2002-06-02 15:01

Message:
Logged In: YES 
user_id=21627

That's not simple at all. Python uses the C library's fgets
function on some systems, which does not support this
feature, either, so you cannot implement it on top of fgets.

If you need to deal with different line end conventions on
various systems, Python 2.3 offers a Universal Newline
Support (PEP 278).

For uses beyond that, I recommend to read the entire file,
then do .split on the resulting string. This is the common
solution to your problem, and it works quite well.

----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=563491&group_id=5470