Why is "while" ticking me off???
Huaiyu Zhu
hzhu at users.sourceforge.net
Thu Oct 5 21:46:59 EDT 2000
On Thu, 05 Oct 2000 19:58:25 -0400, Thomas Gagne <tgagne at ix.netcom.com> wrote:
>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:
This is a recurring theme. There is a reason that Python does not allow
this. There is also a need for this. So something must be done about it.
Here's a little silly Python Extension Proposal:
while line = fp.readline(); line:
do something with line
Similarly:
i = 0
for item in list; i +=1; item:
do something with (i, item)
And
if a = dict1[k1]; a:
do something with a
elif a = dict2[k2]; a<0:
do something else with a
elif a = dict3[k3]; a=="asdsdaf":
do something different with a
And many others. See some more verbose description at
http://www.geocities.com/huaiyu_zhu/python/ififif.txt
Any comments?
Huaiyu
More information about the Python-list
mailing list