operator overloading + - / * = etc...
Antoon Pardon
apardon at forel.vub.ac.be
Tue Oct 10 07:30:27 EDT 2006
On 2006-10-10, Paul Rubin <http> wrote:
> "Fredrik Lundh" <fredrik at pythonware.com> writes:
>> or for the perhaps-overly-clever hackers,
>>
>> for x in iter(lambda: foo() or None, None):
>> process(x)
>
> for x in takewhile(bool, (foo() for _ in repeat(None))):
> process(x)
>
> Meh, both are ugly.
Sure, but so is IMO the current pythonic idiom.
Suppose one has the following intention in mind:
while x = setup():
if y = pre_process() in ErrorCondition:
break
post_process(y)
else:
NormalTermination()
The pythonic idiom for this case would then be something like:
while 1:
x = setup()
if x:
NormalTermination()
break
y = pre_process(x)
if y in ErrorCondition:
break
post_process(y)
There was some time it seemed PEP: 315 would be implemented so
that this could have been written as:
do:
x = setup()
while x:
y = pre_process(x)
if y in ErrorCondition:
break
post_process(y)
else:
NormalTermination()
Which IMO would have been clearer. Alas PEP 315 is deffered so
it will be probably a long time before this will be implemented.
More information about the Python-list
mailing list