esoteric question about dict keys (Re: age of Python programmers)

Alexis Roda alexis.roda at urv.es
Fri Aug 20 12:19:01 CEST 2004


This is my first message to the list, so I'll present myself and add my 
contribution to the "age of python programmes" thread.

My name is Alexis Roda, I'm 36 - 7/365 years old, I started programming 
with python two years ago, mainly because I started playing with zope. 
At first I was a reluctant Perl converted, although initially I hated 
python (well, I hated zope wich make me hate python) now I'm in love 
with both python and zope. I started programming at 15 with a Casio 
calculator (a kind of assembler), then an Amstrad CPC464 (Basic), a 
Macintosh Plus (Pascal, C, Lisp, assembler) and finally come to the 
PC/Linux world (assembler, C, C++, Perl, bash scripting, elisp and python).

Now the question. In "normal" dicts its not possible to use dictionaries 
(nor other kinds of mutable objects) as keys, if I undersand correctly 
this is a technical requirement. If I write my own dictionary-like 
object, on wich the mutability of the keys is not a technical issue, is 
considered blasphemous the use of dicts as keys? For example, querying 
an SQL table can be partially modelled as a dictionary access:

table[pkey_value] gives a record for this primary key

table[{'somefield':somevalue}] returns all the records where 
somefield=somevalue

or is preferable to define a query() method for these uses and restrict 
__getitem__ to mutable objects for the sake of consistency?




TIA
-- 
                                    ////
                                   (@ @)
----------------------------oOO----(_)----OOo--------------------------
<>               Ojo por ojo y el mundo acabara ciego
/\ Alexis Roda - Universitat Rovira i Virgili - Reus, Tarragona (Spain)
-----------------------------------------------------------------------




More information about the Python-list mailing list