[Python-ideas] Extending properties to sequence-like behavior
Dj Gilcrease
digitalxero at gmail.com
Wed Apr 6 08:48:12 CEST 2011
> On Apr 5, 2011, at 10:31 PM, Dan Baker wrote:
>> I want to be
>> able to translate:
>>
>> return box.Items -> return box.GetAllItems()
>> box.Items = itemlist -> box.SetAllItems(itemlist)
>> return box.Items[idx] -> return box.GetItemAtPos(idx)
>> box.Items[idx] = new_item -> box.SetItemAtPos(idx, new_item)
I would translate it to
box.items -> box.GetAllItems()
box.items = itemlist -> box.SetAllItems(itemlist)
box.item[idx] -> box.GetItemAtPos(idx)
box.item[idx] = new_item -> box.SetItemAtPos(idx, new_item)
http://dpaste.com/529172/
Yes you have 2 properties now but it is fairly easy to remember that
items is always getting or setting all of them and item is always
getting or setting a single one
More information about the Python-ideas
mailing list