Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #31141
| From | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| Subject | Re: __setitem__ without position |
| Date | 2012-10-11 19:47 -0400 |
| References | <CA+C4C6c7GBdxs+jZPGNrpauvZXP7caGpPb8Q466HD7mV09731Q@mail.gmail.com> <CA+C4C6eMKa6i4Vk4b7hc8SxyDyutoRKkP9VLt0g3UWs+v5ehTw@mail.gmail.com> <50773AE5.7020400@davea.name> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2075.1349999277.27098.python-list@python.org> (permalink) |
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
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: __setitem__ without position Terry Reedy <tjreedy@udel.edu> - 2012-10-11 19:47 -0400
csiph-web