|
|
|
@ -12,3 +12,22 @@ class Item:
|
|
|
|
|
self.id = int(d['id'])
|
|
|
|
|
self.name = d['name']
|
|
|
|
|
self.price = Decimal(d['price'])
|
|
|
|
|
|
|
|
|
|
def __eq__(self, other):
|
|
|
|
|
for key in ('deposit', 'id', 'name', 'price'):
|
|
|
|
|
if getattr(self, key) != getattr(other, key):
|
|
|
|
|
return False
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
def __ne__(self, other):
|
|
|
|
|
return not self.__eq__(other)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
import copy
|
|
|
|
|
d1 = {'deposit':'0.20', 'id':'15', 'name':'foo bar', 'price':'1.40'}
|
|
|
|
|
d2 = copy.copy(d1)
|
|
|
|
|
a = Item(d1)
|
|
|
|
|
b = Item(d2)
|
|
|
|
|
print(a == b)
|
|
|
|
|
print(a != b)
|
|
|
|
|