Re: Subclassing list and splicing

2009-09-04 Thread Nobody
On Thu, 03 Sep 2009 17:10:12 +, Kreso wrote: > I would prefer that resulting object m belonged to myclist class. > How to obtain such behaviour? Must I somehow implement __getslice__ > method myself? Yes; you should also implement __getitem__(), as this is used for extended slices. -- http:

Re: Subclassing list and splicing

2009-09-03 Thread Kreso
Kreso wrote: [...] > I would prefer that resulting object m belonged to myclist class. I forgot to add that mylist instances in my case have some attributes (that's why I need special container class in the first place) which should be preserved after splicing. In my simple understaning of pyth

Re: Subclassing list and splicing

2009-09-03 Thread Emile van Sebille
On 9/3/2009 10:10 AM Kreso said... I am subclassing list class and it basically works, but I don't understand why after splicing these mylist objects I don't get returned mylist objects. What I get are list objects: I would prefer that resulting object m belonged to myclist class. How to obtai

Re: subclassing 'list'

2009-01-06 Thread akineko
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" wrote: > If you mean you want to r

Re: subclassing 'list'

2009-01-06 Thread J. Cliff Dyer
On Tue, 2009-01-06 at 12:34 -0800, akineko wrote: > Hello everyone, > > I'm creating a class which is subclassed from list (Bulit-in type). > > It works great. > However, I'm having a hard time finding a way to set a new value to > the object (within the class). > There are methods that alter a

Re: subclassing 'list'

2009-01-06 Thread James Stroud
akineko wrote: Hello everyone, I'm creating a class which is subclassed from list (Bulit-in type). It works great. However, I'm having a hard time finding a way to set a new value to the object (within the class). There are methods that alter a part of the object (ex. __setitem__()). But I coul

Re: subclassing 'list'

2009-01-06 Thread Chris Rebert
On Tue, Jan 6, 2009 at 12:34 PM, akineko wrote: > > Hello everyone, > > I'm creating a class which is subclassed from list (Bulit-in type). > > It works great. > However, I'm having a hard time finding a way to set a new value to > the object (within the class). > There are methods that alter a pa

Re: Subclassing list, what special methods do this?

2008-06-14 Thread Paul McGuire
On Jun 13, 1:38 pm, Mike Kent <[EMAIL PROTECTED]> wrote: > For Python 2.5 and new-style classes, what special method is called > for mylist[2:4] = seq and for del mylist[2:4] (given that mylist is a > list, and seq is some sequence)? > > I'm trying to subclass list, and I'm having trouble determini

Re: Subclassing list, what special methods do this?

2008-06-14 Thread Terry Reedy
"Matimus" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] | So, it looks like as long as you want to subclass list, you are stuck | implementing both __*slice__ and __*item__ methods. Unless writing in 3.0, where they have finally disappeared. -- http://mail.python.org/mailman/li

Re: Subclassing list, what special methods do this?

2008-06-14 Thread Mike Kent
On Jun 13, 8:43 pm, Matimus <[EMAIL PROTECTED]> wrote: ...chop... > So, it looks like as long as you want to subclass list, you are stuck > implementing both __*slice__ and __*item__ methods. > > Matt Thanks. That was clear and concise, just what I needed. -- http://mail.python.org/mailman/listi

Re: Subclassing list, what special methods do this?

2008-06-13 Thread Matimus
On Jun 13, 11:38 am, Mike Kent <[EMAIL PROTECTED]> wrote: > For Python 2.5 and new-style classes, what special method is called > for mylist[2:4] = seq and for del mylist[2:4] (given that mylist is a > list, and seq is some sequence)? > > I'm trying to subclass list, and I'm having trouble determin

Re: Subclassing list, what special methods do this?

2008-06-13 Thread Gabriel Genellina
En Fri, 13 Jun 2008 15:38:15 -0300, Mike Kent <[EMAIL PROTECTED]> escribió: For Python 2.5 and new-style classes, what special method is called for mylist[2:4] = seq and for del mylist[2:4] (given that mylist is a list, and seq is some sequence)? I'm trying to subclass list, and I'm having trou

Re: Subclassing list the right way?

2008-04-25 Thread Matimus
On Apr 25, 7:03 am, Kirk Strauser <[EMAIL PROTECTED]> wrote: > I want to subclass list so that each value in it is calculated at call > time. I had initially thought I could do that by defining my own > __getitem__, but 1) apparently that's deprecated (although I can't > find that; got a link?), a

Re: Subclassing list the right way?

2008-04-25 Thread Virgil Dupras
On Apr 25, 4:03 pm, Kirk Strauser <[EMAIL PROTECTED]> wrote: > I want to subclass list so that each value in it is calculated at call > time.  I had initially thought I could do that by defining my own > __getitem__, but 1) apparently that's deprecated (although I can't > find that; got a link?), a

Re: subclassing list

2005-07-31 Thread Robert Kern
spike grobstein wrote: >>You also need to post the code that raises the error, or no one else can > > debug it. > > sorry, I thought I had pasted that line in there, but I guess I missed > it. Here's the full code (after modifying it slightly based on your > post): > > #! /usr/bin/env python >

Re: subclassing list

2005-07-31 Thread spike grobstein
>You also need to post the code that raises the error, or no one else can debug it. sorry, I thought I had pasted that line in there, but I guess I missed it. Here's the full code (after modifying it slightly based on your post): #! /usr/bin/env python def circular_list(list): def __getitem_

Re: subclassing list

2005-07-31 Thread John Machin
spike wrote: > I've googled like crazy and can't seem to find an answer to why this > isn't working. > > I want to create a custom list class that acts as a circular list. > > ie: my_list = (0, 1, 2) Perhaps you mean [0, 1, 2] > > how I want it to behave: > > my_list[0] -> 0 > my_list[1] -> 1

Re: subclassing list

2005-07-31 Thread Robert Kern
spike wrote: > I've googled like crazy and can't seem to find an answer to why this > isn't working. > > I want to create a custom list class that acts as a circular list. > > ie: my_list = (0, 1, 2) > > how I want it to behave: > > my_list[0] -> 0 > my_list[1] -> 1 > my_list[2] -> 2 > my_list[

Re: subclassing list

2004-12-23 Thread Richie Hindle
[Uwe] > How [do] you clear the contents of a list subclass > without creating a new object? Use the paranoia emoticon: "del x[:]". For example: >>> class L(list): ... pass ... >>> x = L() >>> x.append("Spam") >>> del x[:] >>> x [] >>> type(x) >>> with-thanks-to-Gordon-McMillan-ly y'rs, --

Re: subclassing list

2004-12-23 Thread Fuzzyman
class newList(list): def clear(self): self[:] = [] is one way. HTH Regards, Fuzzy http://www.voidspace.org.uk/python/index.shtml -- http://mail.python.org/mailman/listinfo/python-list