subclass list

Jason Orendorff jason at jorendorff.com
Mon Feb 11 17:08:53 EST 2002


Mark McEahern writes:
> Q:  How do I override append() so that I can determine whether to add the
> value or not?
>
> I tried:
>
>   def append(self, value):
>       if not self.unique or (self.unique and not
self.keys.has_key(value)):
>           list.append(value)
>           if self.unique:
>               self.keys[value] = None

list.append(self, value)
  or
super(Bucket, self).append(value)

More on super:
  http://www.python.org/2.2/descrintro.html#cooperation

## Jason Orendorff    http://www.jorendorff.com/





More information about the Python-list mailing list