class Rhash proposal
paolo veronelli
paolo_veronelli at yahoo.it
Wed Jul 14 12:44:40 EDT 2004
Writing software in Python for me it means work with dictionaries.
They are next to humans head.They make no assumption on the names of
variables ,mainly they leave the user
to set his program with the names he like.They track me next to the
user.......etc
Not to bore I ask opinions abuot a very simple new class Rhash :
The name to read as ErHash means recursive hash:
Its implementation:
class Rhash(dict):
def __getitem__(rhash,key):
if key not in rhash:
rhash[key]=Rhash()
return dict.__getitem__(key)
Rhash lets us say:
Human=Rhash()
I=Rhash()
Human['isKindOf']['beast']=None
I['like']['mixing'][('smoking','thinking')]=True
and have no Key Error and don't use the unreadable .setdefault(key,{})
which anyway oblige us to
program the depth in advance.
Would it be nice to have it to help directly dict?
Thanks for comments Paolino
--
....lotta dura per la verdura
More information about the Python-list
mailing list