V
vegetax
How can i make my custom class an element of a set?
class Cfile:
def __init__(s,path): s.path = path
def __eq__(s,other):
print 'inside equals'
return not os.popen('cmp %s %s' % (s.path,other.path)).read()
def __hashcode__(s): return s.path.__hashcode__()
the idea is that it accepts file paths and construct a set of unique
files (the command "cmp" compares files byte by byte.),the files can
have different paths but the same content
but the method __eq__ is never called
class Cfile:
def __init__(s,path): s.path = path
def __eq__(s,other):
print 'inside equals'
return not os.popen('cmp %s %s' % (s.path,other.path)).read()
def __hashcode__(s): return s.path.__hashcode__()
the idea is that it accepts file paths and construct a set of unique
files (the command "cmp" compares files byte by byte.),the files can
have different paths but the same content
but the method __eq__ is never called