subclassing 'list'

akineko akineko at gmail.com
Tue Jan 6 16:11:00 EST 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!
Aki-


On Jan 6, 12:43 pm, "Chris Rebert" <c... at rebertia.com> 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 mbi.ucla.edu> 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