Created
August 14, 2014 12:44
-
-
Save damnit/89bb50ed7eaac89abe16 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 -*- | |
from __future__ import print_function | |
import hashlib | |
class City(object): | |
""" This is the Foo object | |
""" | |
def __init__(self, name, population): | |
self._name = name | |
self._population = population | |
@property | |
def name(self): | |
return self._name | |
@property | |
def population(self): | |
return self._population | |
def __repr__(self): | |
""" representation of foo. | |
""" | |
return '<Foo: %s|%s>' % (self.name, self.population) | |
def __hash__(self): | |
hashstring = '%s%s' % (self.name, self.population) | |
hd = hashlib.md5(hashstring.encode('utf-8')).hexdigest() | |
return int(hd, 16) | |
def __eq__(self, other): | |
nam = (other.name == self.name) | |
pop = (other.population == self.population) | |
return True if nam and pop else False | |
if __name__ == '__main__': | |
s = City('Stuttgart', 75000) | |
r = City('Ravensburg', 40000) | |
t = City('Ravensburg', 40000) | |
bar = set() | |
bar.add(s) | |
bar.add(r) | |
bar.add(t) | |
from IPython import embed; embed() | |
# vim: set ft=python ts=4 sw=4 expandtab : |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment