Is it safe to modify the dict returned by vars() or locals()

Duncan Booth duncan.booth at invalid.invalid
Tue Dec 2 10:50:31 CET 2008

Helmut Jarausch <jarausch at> wrote:

> Chris Rebert wrote:
>> On Mon, Dec 1, 2008 at 1:01 PM, Helmut Jarausch <jarausch at>
>> wrote: 
>>> Hi,
>>> I am looking for an elegant way to solve the following problem:
>>> Within a function
>>> def Foo(**parms)
>>> I have a list of names, say  VList=['A','B','C1']
>>> and I like to generate abbreviation
>>> _A identical to parms['A']
>> Could you explain what you mean by that? Your sample code doesn't
>> seem to do any "abbreviation"...
>> Otherwise I don't see why you don't just have a proper parameter
>> list. 
> In my application parms contains field names of an html form iff these
> fields have been modified.
> I'd like to use the short name  _A  instead of the longer expression
> parms['A'] 
You haven't yet explained why you don't just do:

def foo(A=None, **parms):

The code to call foo remains the same as before, but Python will unpack 
the named parameter into the local variable A for you automatically. Any 
other parms that you didn't know about in advance remain in the separate 

Duncan Booth

More information about the Python-list mailing list