Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #31141 > unrolled thread
| Started by | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| First post | 2012-10-11 19:47 -0400 |
| Last post | 2012-10-11 19:47 -0400 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: __setitem__ without position Terry Reedy <tjreedy@udel.edu> - 2012-10-11 19:47 -0400
| From | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| Date | 2012-10-11 19:47 -0400 |
| Subject | Re: __setitem__ without position |
| Message-ID | <mailman.2075.1349999277.27098.python-list@python.org> |
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 top | Article view | comp.lang.python
csiph-web