[Tutor] class methods as argument
Kent Johnson
kent37 at tds.net
Sat Feb 10 17:50:20 CET 2007
thomas coopman wrote:
> On Sat, 10 Feb 2007 09:04:15 -0500
> Kent Johnson <kent37 at tds.net> wrote:
>> If you do want to keep FooList then you should call
>> SortedList.__init__() to set the compare function.
>> SortedList.__init__ is an unbound function so you call it like this:
>> SortedList.__init__(self, Foo.compare)
> This works.
> I think I'll need to reed some more about super because I thought I had
> to use super in this case.
You can use super() also but for simple cases I think it is fine to just
call the superclass method directly. super() is intended to help with
some of the difficulties of multiple inheritance but it has some
difficulties of its own.
> I mostly need the sorted list, because I want to detect when a object
> is added with the same value of some item in the list and take
> appropriate actions.
If you don't really care about the order, then a dict mapping the value
of interest to a list of items with that value might be easier to work with.
Kent
More information about the Tutor
mailing list