Skip to content

Instantly share code, notes, and snippets.

@thulio
Forked from daltonmatos/mocktrue.py
Created August 7, 2012 03:05
Show Gist options
  • Save thulio/3280965 to your computer and use it in GitHub Desktop.
Save thulio/3280965 to your computer and use it in GitHub Desktop.
Hack to mock the python True object
class True(object):
def __init__(self, iterations=1):
self.iterations = iterations
self.current_iteration = 0
def __nonzero__(self):
if self.current_iteration < self.iterations:
self.current_iteration += 1
return 1
return 0
if __name__ == "__main__":
True = True(4)
while True:
print "Loop!"
daltonmatos@jetta wsgid % python mocktrue.py
Loop!
Loop!
Loop!
Loop!
daltonmatos@jetta wsgid %
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment