Created
November 21, 2011 11:27
-
-
Save shomah4a/1382368 to your computer and use it in GitHub Desktop.
こんなん?
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
#-*- coding:utf-8 -*- | |
class CaseClassLike(object): | |
def __init__(self, **argd): | |
self.__dict__.update(argd) | |
def __eq__(self, other): | |
if self is other: | |
return True | |
return self.__dict__ == other.__dict__ | |
def update(self, **argd): | |
ret = CaseClassLike(**self.__dict__) | |
ret.__dict__.update(argd) | |
return ret | |
def __str__(self): | |
return '<CaseClass %s>' % self.__dict__ | |
if __name__ == '__main__': | |
x = CaseClassLike(a=10, b=20) | |
y = CaseClassLike(a=10, b=20) | |
print 'x', x | |
print 'y', y | |
print x == y # True | |
z = x.update(c=10) | |
print x == z # False | |
print 'z', z |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment