-
-
Save thulio/3280965 to your computer and use it in GitHub Desktop.
Hack to mock the python True object
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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