Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: __setitem__ without position

Thread Tools

Re: __setitem__ without position

Terry Reedy
Posts: n/a
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 __setitem__ to recognize that the 'key' is a
slice object rather than an int and act accordingly. (In 2.x, you would
write __setslice__.) Actually, if you write

def __setitem__(self, key, value):
self.somelist[key] = value

as you might have done already, you get slice getting, setting, and
deleting for free. Try Dave's line in your code.

Terry Jan Reedy

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: __setitem__ without position Peter Otten Python 0 10-12-2012 04:42 PM
Re: __setitem__ without position Ethan Furman Python 0 10-12-2012 04:16 PM
Re: __setitem__ without position Ethan Furman Python 0 10-11-2012 11:23 PM
Re: __setitem__ without position Ian Kelly Python 0 10-11-2012 10:43 PM
Re: __setitem__ without position Dave Angel Python 0 10-11-2012 09:32 PM