Why is "while" ticking me off???
tyler at tylereaves.com
Fri Oct 6 03:01:10 CEST 2000
On Thu, 05 Oct 2000 19:58:25 -0400, Thomas Gagne
<tgagne at ix.netcom.com> wrote:
for x in a:
>I have a file that I want to read line-by-line, and stop reading when I run
>out of lines. My first desire was to attempt:
>while line = fp.readline():
> do something with 'line'
>but that doesn't work because Python doesn't allow assignments inside flow
>control statements. The example I see in books is pretty useless:
> count = count + 1
>because if I don't capture the return value of fp.readline() I'm kinda hosed,
>I would try a do:, but there isn't one, is there? At least not one documented
>in, "The Quick Python Book."
>So I thought I'd try something like:
>def myReadline(fp, line):
> line = fp.readline()
> return line
>while myReadline(theFpImReading, data):
>but 'data' doesn't seem to get mutated from the myReadline function!
>I'm obviously not approaching this in the Python idiomatic way.
Visit Ultra Coaster Central!
The internet's largest repository
of Ultra Coaster Tracks!
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 80,000 Newsgroups - 16 Different Servers! =-----
More information about the Python-list