[Patches] [ python-Patches-516297 ] iterator for lineinput

noreply@sourceforge.net noreply@sourceforge.net
Sun, 24 Mar 2002 20:35:32 -0800


Patches item #516297, was opened at 2002-02-12 03:56
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=305470&aid=516297&group_id=5470

Category: Library (Lib)
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Brett Cannon (bcannon)
Assigned to: Neil Schemenauer (nascheme)
Summary: iterator for lineinput

Initial Comment:
Taking the route of least evasiveness, I have come up with
a VERY simple iterator interface for fileinput.

Basically, __iter__() returns self and next() calls
__getitem__() with the proper number.  This was done to
have the patch only add methods and not change any
existing ones, thus minimizing any chance of breaking
existing code.

Now the module on the whole, however, could possibly
stand an update now that generators are coming.  I have
a recipe up at the Cookbook that uses generators to
implement fileinput w/o in-place editing
(http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/112506).
 If there is enough interest, I would be quite willing
to rewrite fileinput using generators.  And if some of
the unneeded methods could be deprecated (__getitem__,
readline), then the whole module could probably be
cleaned up a decent amount and have a possible speed
improvement.

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

>Comment By: Neil Schemenauer (nascheme)
Date: 2002-03-25 04:35

Message:
Logged In: YES 
user_id=35752

Why do you need fileinput to have a __iter__ method?  As
far as I can see it only slows things down.  As it is now
iter(fileinput.input()) works just fine.  Adding __iter__
and next() just add another layer of method calls.



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

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