ordered keywords?

Diez B. Roggisch deets at nospam.web.de
Mon Oct 17 15:27:31 EDT 2005


Ron Adam wrote:
> 
> Is there a way to preserve or capture the order which keywords are given?
> 
>  >>> def foo(**kwds):
> ...    print kwds
> ...
>  >>> foo(one=1, two=2, three=3)
> {'three': 3, 'two': 2, 'one': 1}
> 
> 
> I would love to reverse the *args, and **kwds as well so I can  use kwds 
> to set defaults and initiate values and args to set the order of 
> expressions.
> 
> 
> def foo(**__dict__, *args):
>       print args
> 
> print foo(x=10, y=20, x, y, x+y)
> [10, 20, 30]

This is not simply about reversing the order of kwargs and args - this 
would require that keyword args would create bindings to variable names 
in the scope of the caller. Which is an enterily different beast. And a 
major semantic change in python, so it's not possible or at least not 
happening before Python 3K.

Regards,

Diez




More information about the Python-list mailing list