custom classes in sets

vegetax vegeta.z at gmail.com
Mon Feb 14 01:40:44 EST 2005


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




More information about the Python-list mailing list