No-brainer? Dictionary keys to variable name?

Max M maxm at mxm.dk
Thu Aug 1 16:28:04 EDT 2002


Christopher Myers wrote:
> I'm re-implementing some code that I wrote, and I don't want to rewrite
> more than I have to.
> 
> Specifically, I'm looking for a way to take a dictionary, e.g.
> { "a" : 1, "b" : 2, "c" : 3 }
> 
> and convert it into something like
> 
> a = 1
> b = 2
> c = 3


You don't need that step!


> so that the keys are the actual variable names and the values are
> obviously the variables' values.
> 
> The reason I'm trying to do this is I have a method as follows:
> 
>     def runSearchTest(self, script_url, f_title="", leftquery="", 
>                           findwords="titlestext", part="", 
>                           categories="all", categval=(), 
>                           topics="all", topicvalue=() ):
> 
> And I've changed my mind about the implementation.  I'd like to change
> the parameters to 
> 
>     def runSearchTest(self, oneTest={}):


def runSearchTest(self, **theDict):

regards Max M




More information about the Python-list mailing list