Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
72ea28ce
Commit
72ea28ce
authored
Mar 26, 2002
by
Neil Schemenauer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement iterator protocol.
parent
782b8702
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
4 deletions
+13
-4
Lib/fileinput.py
Lib/fileinput.py
+13
-4
No files found.
Lib/fileinput.py
View file @
72ea28ce
...
...
@@ -166,7 +166,10 @@ class FileInput:
self
.
nextfile
()
self
.
_files
=
()
def
__getitem__
(
self
,
i
):
def
__iter__
(
self
):
return
self
def
next
(
self
):
try
:
line
=
self
.
_buffer
[
self
.
_bufindex
]
except
IndexError
:
...
...
@@ -176,13 +179,19 @@ class FileInput:
self
.
_lineno
+=
1
self
.
_filelineno
+=
1
return
line
if
i
!=
self
.
_lineno
:
raise
RuntimeError
,
"accessing lines out of order"
line
=
self
.
readline
()
if
not
line
:
raise
IndexError
,
"end of input reached"
raise
StopIteration
return
line
def
__getitem__
(
self
,
i
):
if
i
!=
self
.
_lineno
:
raise
RuntimeError
,
"accessing lines out of order"
try
:
return
self
.
next
()
except
StopIteration
:
raise
IndexError
,
"end of input reached"
def
nextfile
(
self
):
savestdout
=
self
.
_savestdout
self
.
_savestdout
=
0
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment