operator overloading + - / * = etc...
Paul Rubin
http
Tue Oct 10 08:24:16 EDT 2006
Antoon Pardon <apardon at forel.vub.ac.be> writes:
> Suppose one has the following intention in mind:
>
> while x = setup():
> if y = pre_process() in ErrorCondition:
> break
> post_process(y)
> else:
> NormalTermination()
Maybe we need a new itertools function:
def forever(func, *args, **kw):
while True:
yield func(*args, **kw)
then you'd write:
for x in takewhile(bool, forever(setup)):
if y = pre_process() in ErrorCondition:
break
post_process(y)
else:
NormalTermination()
It might be preferable to write pre_process to raise an exception if
there's an error condition. Then the whole thing becomes:
try:
for x in takewhile(bool, forever(setup)):
post_process(pre_process())
NormalTermination()
except PreprocessError:
pass
More information about the Python-list
mailing list