On 16/05/13 23:50, Ethan Furman wrote:
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.
Free like a puppy :-)
You make a good point. Perhaps "free" was a bad choice of words. Rather, let me say that if you need ordered keyword arguments, you can have them *right now* without waiting for the day when you can drop support for everything older that Python 3.4 (or whatever version gives you order-preserving kwargs).