k4ever/client-barcode/freitagslib/item.py

34 lines
739 B
Python

#! /usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (C) 2011 Sebastian Pipping <sebastian@pipping.org>
# Licensed under GPL v3 or later
from decimal import Decimal
class Item:
def __init__(self, d):
self.deposit = Decimal(d['deposit'])
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)