[Python-ideas] Let's be more orderly!

Ethan Furman ethan at stoneleaf.us
Thu May 16 15:50:23 CEST 2013


On 05/15/2013 08:16 PM, Steven D'Aprano wrote:
>
> I don't believe it can. Hence, when order is important, you cannot use keyword arguments to provide arguments *even if
> kwargs are ordered*. But if you write your function like this:
>
> def create_element(tag, mapping):
>      pass
>
> and call it like this:
>
> create_element('img', OrderedDict([('alt', 'something'), ('src', 'something.jpg')]))
>
> then you can get order for free. Yes, it's a little less convenient to use a list of tuples than nice keyword syntax,
> but that's a solution that doesn't impose any costs on code that doesn't care about ordering.

Which 'free' are you talking about?  Because if the solution requires extra typing and extra visual clutter, it's not free.

--
~Ethan~


More information about the Python-ideas mailing list