Re: __setitem__ without position

2012-10-12 Thread Ethan Furman
Terry Reedy wrote: In 3.x, you would write __setitem__ to recognize that the 'key' is a slice object rather than an int and act accordingly. (In 2.x, you would write __setslice__.) I'm not sure how far back it goes, but at least from 2.4 forward __setitem__ works with slices just fine.

Re: __setitem__ without position

2012-10-12 Thread Peter Otten
Ethan Furman wrote: Terry Reedy wrote: In 3.x, you would write __setitem__ to recognize that the 'key' is a slice object rather than an int and act accordingly. (In 2.x, you would write __setslice__.) I'm not sure how far back it goes, but at least from 2.4 forward __setitem__ works with

__setitem__ without position

2012-10-11 Thread Kevin Anthony
I have a class that contains a list of items I can set items using __setitem__ but if i want to set the while list, i changes the variable from a myclass to a list. How can i accomblish this Example C = myclass() C[0] = 57 type(C) myclass C = [57,58,59,60] type(C) list --

Re: __setitem__ without position

2012-10-11 Thread Dave Angel
On 10/11/2012 04:48 PM, Kevin Anthony wrote: I have a class that contains a list of items I can set items using __setitem__ but if i want to set the while list, i changes the variable from a myclass to a list. How can i accomblish this Example C = myclass() C[0] = 57 type(C) myclass C =

Re: __setitem__ without position

2012-10-11 Thread Kevin Anthony
I'm not supprised... and understand why it's happening. I'm asking how to get around it. Basically i'm asking how to override, if i can, the `=` On Thu, Oct 11, 2012 at 5:32 PM, Dave Angel d...@davea.name wrote: On 10/11/2012 04:48 PM, Kevin Anthony wrote: I have a class that contains a

Re: __setitem__ without position

2012-10-11 Thread Ian Kelly
On Thu, Oct 11, 2012 at 4:13 PM, Kevin Anthony kevin.s.anth...@gmail.com wrote: I'm not supprised... and understand why it's happening. I'm asking how to get around it. Basically i'm asking how to override, if i can, the `=` You cannot override assignment of local variables. To get around

Re: __setitem__ without position

2012-10-11 Thread Terry Reedy
On 10/11/2012 5:32 PM, Dave Angel wrote: Alternatively, you could call one of the other methods in the class. But since you gave us no clues, I'm shouldn't guess what it was called. But if I were to make such a class, I might use slicing: C[:] = [57, 50, 59, 60] In 3.x, you would write

Re: __setitem__ without position

2012-10-11 Thread Ethan Furman
Kevin Anthony wrote: I'm not supprised... and understand why it's happening. I'm asking how to get around it. I don't think you do understand what's happening. What's happening is the basic application of name binding in Python: -- C = anything whatever C was bound to before, it no longer