Last active
December 23, 2015 18:29
-
-
Save DeaconDesperado/6675588 to your computer and use it in GitHub Desktop.
Python conditional truthiness is len by default
This file contains hidden or 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 Dummy(object): | |
def __init__(self,foo): | |
self.foo = foo | |
def __len__(self): | |
#This will make me always falsy, define and __nonzero__ method! | |
return 0 | |
def __gt__(self,other): | |
return self.foo > other | |
def __lt__(self,other): | |
return self.foo < other | |
def __eq__(self,other): | |
return self.foo == other | |
d = Dummy(200) | |
if d: | |
print 'This wont ever print, dummy! Define a __nonzero__ method!' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment