Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #12550

Re: idiomatic analogue of Perl's: while (<>) { ... }

From Peter Otten <__peter__@web.de>
Subject Re: idiomatic analogue of Perl's: while (<>) { ... }
Date 2011-09-01 09:43 +0200
Organization None
References <20110901045650.GA3466@magic.hamla.org> <j3n8r3$heg$1@dough.gmane.org>
Newsgroups comp.lang.python
Message-ID <mailman.647.1314862977.27778.python-list@python.org> (permalink)

Show all headers | View raw


Peter Otten wrote:

> A quick look into fileinput.py reveals that it uses readlines() and slurps
> in the complete "file". I'm not sure that was a clever design decision...

Correction: 

>>> with open("tmp.txt") as f: lines = f.readlines(0)
...
>>> len(lines)
1000000
>>> with open("tmp.txt") as f: lines = f.readlines(1)
...
>>> len(lines)
301
>>> len("".join(lines))
8208

So on my system file.readlines(size) stops after about 2**13 bytes which is 
not a problem memorywise. Sorry for the confusion.

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: idiomatic analogue of Perl's: while (<>) { ... } Peter Otten <__peter__@web.de> - 2011-09-01 09:43 +0200

csiph-web