T
Thomas Nelson
Occasionally people post complaining about the lack of a
"repeat...until" structure in python. I thought about it and came up
with this recipe that I like. The only ugly thing is having to use
lambdas, otherwise it's very terse and readable. Tell me what you
think, and if anyone besides me thinks they might use it, I'll post it
to the python cookbook.
Thanks for your time,
Tom
class Until:
""" ... print "hello"
... i += 1
hello
hello
hello ... print "hello"
hello
"""
yet = True
def __init__(self, mybool):
if self.__class__.yet or mybool():
self.__class__.yet = False
self.ans = True
else:
self.__class__.yet = True
self.ans = False
def __nonzero__(self):
return self.ans
"repeat...until" structure in python. I thought about it and came up
with this recipe that I like. The only ugly thing is having to use
lambdas, otherwise it's very terse and readable. Tell me what you
think, and if anyone besides me thinks they might use it, I'll post it
to the python cookbook.
Thanks for your time,
Tom
class Until:
""" ... print "hello"
... i += 1
hello
hello
hello ... print "hello"
hello
"""
yet = True
def __init__(self, mybool):
if self.__class__.yet or mybool():
self.__class__.yet = False
self.ans = True
else:
self.__class__.yet = True
self.ans = False
def __nonzero__(self):
return self.ans