Using Dictionary look-up
kacmaz at my-deja.com
kacmaz at my-deja.com
Tue Dec 5 23:38:43 EST 2000
This is kind of a follow-up to an earlier question I posted. Thankyou
for all who answered it....
I have written a simple dictionary look up where necessary values are
received from a single-item dictionary (later on I will open this up to
a larger number of items..!) (I saw a similar one in Mr Guido's site I
think!).....
The dictionary would be {'UserXXXX':'123123'}
----Configuration.py (start)----
...
UserName=UserXXXX
UserNumb="123123"
...
----Configuration.py (ends)----
----Main.py (start)----
...
from configuration import *
class Authenticator:
def __init__(self):
self.authenticate=Dict_lookup(UserName=function(UserNumb))
def lookup_key (self,*args):
return apply(self.authenticate.lookup_key,args)
class Dict_lookup:
def __init__(self,**kw):
self.dict=kw
def lookup_key (self,sn):
return self.dict[sn]
...
----Main.py (ends)----
But python gives me error when I run it like this as :
Exceptions.KeyError : UserName
but still if I change the above line with :
def __init__(self):
self.authenticate=Dict_lookup(UserXXXX=function(UserNumb))
then it works fine...!!!
The general structure of the dict_lookup suits what I want to do but
why can't I call up UserName in this fashion?
thanks
HK
Sent via Deja.com http://www.deja.com/
Before you buy.
More information about the Python-list
mailing list