How to store the reference of a dictionary element ?

Robin Munn rmunn at pobox.com
Fri Dec 20 12:29:42 EST 2002


Mike Meyer <mwm at mired.org> wrote:
> Mike Meyer <mwm at mired.org> writes:
> 
>> Ok, now the solution is easy. Don't use lists. Use your own class that
>> look like lists:
>> 
>> class MenuList(list):
>>    def __setitem__(index, item): my[index][0] = item
>>    def __getitem__(index): return my[index][0]
> 
> Sigh. Of course that should be:
> 
> class MenuList(list():
>    def __setitem__(my, index, item): my[index][0] = item
>    def __getitem__(my, index): return my[index][0]
> 

Oh. Now I understand -- you've used "my" where nearly everyone uses
"self". Python will let you do that, but (as I just accidentally
demonstrated) it will be easier for other people to understand your code
if you go with the generally-accepted convention of using "self".

-- 
Robin Munn <rmunn at pobox.com>
http://www.rmunn.com/
PGP key ID: 0x6AFB6838    50FF 2478 CFFB 081A 8338  54F7 845D ACFD 6AFB 6838



More information about the Python-list mailing list