[Python-Dev] Issue 6081: format string using mapping rather than kwargs
Nick Coghlan
ncoghlan at gmail.com
Thu Mar 25 12:00:35 CET 2010
Filip GruszczyĆski wrote:
> I would appreciate any advice on this topic, even if this ticket would
> be dismissed altogether, as I would like to learn as much as possible
> on practices on developing Python.
Raymond's use case is valid, but the currently proposed method name is
way too long to be usable and the use of *args is a definite misfeature.
I suggest approaching the issue with the exact spec needed to cover the
problem Raymond described:
Add a method to strings that allows a format string to
be applied to an existing mapping without implicitly
converting the mapping to a dict first.
>From that spec, a straightforward API falls out:
def format_mapping(self, kwds):
# Method body actually written in C, so it can
# easily invoke the internal formatting operation
return do_string_format(self, NULL, kwds)
Sure, you can't mix positional and keyword arguments the way you can
with .format(), but you can't mix and match those with mod-formatting
either.
*If* support for a sequence were to be added (and that's a big if), it
should be added as an explicit second argument, not as a *args argument.
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
---------------------------------------------------------------
More information about the Python-Dev
mailing list