feedback on Until recipe

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,264
Messages
2,571,065
Members
48,769
Latest member
Clifft

Latest Threads

Top