467,136 Members | 1,254 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,136 developers. It's quick & easy.

feedback on Until recipe

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:
"""
>>i = 0
while Until(lambda: i<3):
... print "hello"
... i += 1
hello
hello
hello
>>while Until(lambda: i<2):
... 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

Apr 24 '07 #1
  • viewed: 777
Share:

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Dan Perl | last post: by
8 posts views Thread by Michele Simionato | last post: by
36 posts views Thread by Remi Villatel | last post: by
1 post views Thread by Nicholas Zhou | last post: by
1 post views Thread by Dgates | last post: by
8 posts views Thread by Richard Hollenbeck | last post: by
6 posts views Thread by placid | last post: by
17 posts views Thread by Ron Adam | last post: by
7 posts views Thread by Thomas Nelson | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.