[ python-Feature Requests-1152248 ] Enhance file.readlines by making line separator selectable

SourceForge.net noreply at sourceforge.net
Mon Jun 27 13:22:24 CEST 2005


Feature Requests item #1152248, was opened at 2005-02-26 01:24
Message generated for change (Comment added) made by montanaro
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=355470&aid=1152248&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Interpreter Core
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Nick Coghlan (ncoghlan)
Assigned to: Nobody/Anonymous (nobody)
Summary: Enhance file.readlines by making line separator selectable

Initial Comment:
There is no canonical way to iterate through a file on
chunks *other* than whole lines without reading the
whole file into memory.

Allowing the separator to be specified as an argument
to file.readlines and file.xreadlines would greatly
simplify the task.

See here for an example interface of the useful options:
http://mail.python.org/pipermail/python-list/2005-February/268482.html

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

>Comment By: Skip Montanaro (montanaro)
Date: 2005-06-27 06:22

Message:
Logged In: YES 
user_id=44345

Seems the most likely place you'd want to use this is to select a non-
native line ending in a situation where you didn't want to use universal
newlines (select \r as a line ending on Unix, for example, and allow
\n to just be another character).  In that case they'd clearly still be
lines, so embellishing the normal line reading machinery without
adding a new method would be most appropriate.


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

Comment By: Nick Coghlan (ncoghlan)
Date: 2005-06-27 04:29

Message:
Logged In: YES 
user_id=1038590

As Douglas Alan's sample implementation (and his second
attempt [1]) show, getting this right (and reasonably
efficient) is actually a non-trivial exercise. Leveraging
the existing readlines infrastructure is an idea worth
considering.

[1]
http://mail.python.org/pipermail/python-list/2005-February/268547.html

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

Comment By: Raymond Hettinger (rhettinger)
Date: 2005-06-26 23:25

Message:
Logged In: YES 
user_id=80475

The OPs request is not a non-starter.  There is a proven 
precedent in AWK which allows programmer specifiable record 
separators.

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

Comment By: Douglas Alan (nessus42)
Date: 2005-02-28 12:57

Message:
Logged In: YES 
user_id=401880

In reply to birkenfeld, I'm not sure why you don't want to
call lines separated with an alternate line-separation
string "lines", but if you want to call them something else,
I should think they should be called "records" rather than
"chunks".

|>oug


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

Comment By: Reinhold Birkenfeld (birkenfeld)
Date: 2005-02-26 01:38

Message:
Logged In: YES 
user_id=1188172

I don't know whether (x)readlines is the right place, since
you are _not_ operating on lines.

What about (x)readchunks?

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

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=355470&aid=1152248&group_id=5470


More information about the Python-bugs-list mailing list