Using dictionaries

Alex Martelli aleaxit at
Wed Dec 6 04:26:06 EST 2000

"sorular" <sorular at> wrote in message
news:3a2dca59.583722939 at
> The dictionary would be {'UserXXXX':'123123'}
> (start)----
> ...
> UserName=UserXXXX
> UserNumb="123123"
> ...

I'll assume you mean


as these quotes are really crucial.

> self.authenticate=Dict_lookup(UserName=function(UserNumb))

This passes to this __init__:

> class Dict_lookup:
>     def __init__(self,**kw):
>         self.dict=kw

a 'kw' dictionary like {'UserName': function(UserNumb)}.

In other words, in the sintax:


aname is NOT looked up anywhere: {'aname': avalue} is the
resulting keywords-dictionary (which the callable can
retrieve as **kw).  'aname' is taken as *constant* in
this syntactic form.

Try, instead (Python 2 syntax):


here, you are explicitly building and passing the keywords
dictionary, rather than relying on it being built for you
by the Python compiler and interpreter; so, you can use any
expressions you desire for the keys as well as for the values,
rather than being limited to constant keys as in the name=value

Alternatively, save yourself the double stars on both the
call and the function definition:

class Dict_lookup:
    def __init__(self,kw):


and the net effect will be the same (though it will also
work on older versions of Python; the double-stars syntax
on the call only works in Python 2).


More information about the Python-list mailing list