mirror of
https://github.com/python/cpython.git
synced 2025-11-25 12:44:13 +00:00
Add readlines() to _Subfile class. Not clear who would need it, but
Chris Lawrence sent me a broken version; this one is a tad simpler and more conforming to the standard.
This commit is contained in:
parent
9b8afdee44
commit
e256a0feed
1 changed files with 13 additions and 0 deletions
|
|
@ -66,6 +66,19 @@ class _Subfile:
|
|||
self.pos = self.fp.tell()
|
||||
return data
|
||||
|
||||
def readlines(self, sizehint = -1):
|
||||
lines = []
|
||||
while 1:
|
||||
line = self.readline()
|
||||
if not line:
|
||||
break
|
||||
lines.append(line)
|
||||
if sizehint >= 0:
|
||||
sizehint = sizehint - len(line)
|
||||
if sizehint <= 0:
|
||||
break
|
||||
return lines
|
||||
|
||||
def tell(self):
|
||||
return self.pos - self.start
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue