subclassing 'list'

akineko akineko at
Tue Jan 6 22:11:00 CET 2009

Hello Chris and James,

Thank you for you guys' prompt response.
Yes, that is what I wanted to do.
I, somehow, didn't think of using those list methods.
Instead, I was looking for a single method to override.

Big Thanks!

On Jan 6, 12:43 pm, "Chris Rebert" <c... at> wrote:
> If you mean you want to replace the contents of the list with that of
> another list, just do:
> def arrange(self):
>     self.clear() #empty the list
>     self.extend(new_list) #append the contents of other list

On Jan 6, 12:45 pm, James Stroud <jstr... at> wrote:
> Slice assignment will behave as you like:
> py> class Mylist(list):
> ...     def arrange(self):
> ...         new_value = [1, 2, 3]
> ...         self[:] = new_value
> ...

More information about the Python-list mailing list