Skip to content

Instantly share code, notes, and snippets.

@shomah4a
Created November 21, 2011 11:27
Show Gist options
  • Save shomah4a/1382368 to your computer and use it in GitHub Desktop.
Save shomah4a/1382368 to your computer and use it in GitHub Desktop.
こんなん?
#-*- 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