Why is "while" ticking me off???
Huaiyu Zhu
hzhu at users.sourceforge.net
Fri Oct 6 13:40:00 EDT 2000
More information about the Python-list mailing list
Fri Oct 6 13:40:00 EDT 2000
- Previous message (by thread): Why is "while" ticking me off???
- Next message (by thread): Why is "while" ticking me off???
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Fri, 06 Oct 2000 16:13:41 +0100, Alan Gauld <alan.gauld at gssec.bt.co.uk> wrote: >Thomas Gagne wrote: >> while line = fp.readline(): >> do something with 'line' >> >> but that doesn't work because Python doesn't allow assignments > >correct, so at the expense of typing a line twice, do >the assignment externally: The expense could be high in real codes, not just a line or two. See http://www.geocities.com/huaiyu_zhu/python/ififif.txt I quote an example here: if val = dict1[key1]: process1(val) elif val = dict2[key2]: process2(val) elif val = dict3[key3]: process3(val) ... The entirely equivalent python code would require nested ifs val = dict1[key1] if val: process1(val) else: val = dict2[key2] if val: process2(val) else: val = dict3[key3] if val: process3(val) else: ... Huaiyu
- Previous message (by thread): Why is "while" ticking me off???
- Next message (by thread): Why is "while" ticking me off???
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list