[Chicago] order of keyword arguments

kirby urner kirby.urner at gmail.com
Sat Feb 7 05:48:09 CET 2009

On Thu, Feb 5, 2009 at 4:20 AM, Igor Sylvester <igorsyl at gmail.com> wrote:
> Thanks for your comments.
> Doesn't it just go against the design of Python?  Dictionaries don't
> care about order, so if you do, use something other than a dictionary?
>  You can pass a list or something?  Don't use the **kwargs feature?
> $0.02
> My suggestion is not to change the dict object but perhaps make kwargs an
> instance of a subclass of dict.  The kwargs instance would know about the
> ordering of the keyword arguments.

The thing is you're not required to pass arguments as a dictionary,
and if the order really matters, then you probably shouldn't.

However if order does matter and you must pass to **kwargs, you could
have a special function that takes the assignments and seeds a
dictionary with argument order info e.g.

orderargs(egg=17, chicken=56) gives back...

{('chicken':(17,1), 'egg':(56,0)}   # the tuple encodes ordering info

...for then passing to your **kwargs.

You could go myfunction ( orderargs(b=17, a=56) ) and have your
myfunction aware of which came first.


More information about the Chicago mailing list