Entry
How to use Dictionary look-up
Dec 7th, 2000 17:51
hasan kacmaz, aleaxit@yahoo.com;
This is what I think would help, if one wants to use a dictionary look-
up as a value within a code that requires some configuration input. For
example, a dictionary look-up with dictionary['username'] should bring
up the user number etc...
the syntax below should do a dict-lookup where it's called within a
keywords-dictionary which callable can retrieve as **kw (ie. callable
(aname)) :
class Dictionary:
self.dictionary=Dict_lookup(UserName)
def lookup_key
return apply(self.dictionary.lookup_key,args)
class Dict_lookup:
def __init__(self,**kw):
self.dict=kw
def lookup_key (self,sn):
return self.dict[sn]
Alex Martelli has pointed out another way for the case where one
dictionary value called in a function...
ie.
class Dict_lookup:
def __init__(self,kw):
self.dict=kw
self.dictionary=Dict_lookup({UserName:function(UserNumb)})
OR (for python 2.0...!)
self.authenticate=Dict_lookup(**{UserName:function(UserNumb)})
HK