pyformat.info icon indicating copy to clipboard operation
pyformat.info copied to clipboard

Keyword arguments are possible with placeholders

Open wolph opened this issue 8 years ago • 4 comments

Using a dict() to allow for keyword arguments is the obvious alternative for the new-style keyword arguments. It's a bit odd to say that this sn't supported.

wolph avatar Mar 18 '17 22:03 wolph

Thanks for the PR.

However I think it's a question of semantics whether you'd call this form "keyword arguments". Sure dict accepts kwargs but IMO that has little to do with the % formatting call.

ulope avatar May 09 '17 17:05 ulope

I suppose it is, but it's a commonly used technique so it would be good to document that regardless of whether it's related to the formatting call.

wolph avatar May 09 '17 17:05 wolph

I don't know that the split even makes sense, fundamentally the first section is already using keyword arguments: % uses dicts for named placeholders while format uses keyword arguments (though there is format_map). I think it'd be more sensible to use both in the first example, and add a note pointing out ** or str.format_map in the specific case where one already has a dict object.

xmo-odoo avatar Feb 13 '19 09:02 xmo-odoo

In any case, I think this should document an alternative solution for common use cases and for the projects I've seen the dict approach is common enough so it should be added.

@ulope will this get merged or should I just close it?

wolph avatar Feb 21 '19 17:02 wolph