[Python-Dev] str.format_from_mapping (original) (raw)

Antoine Pitrou solipsis at pitrou.net
Sun Oct 31 22:08:17 CET 2010


On Sun, 31 Oct 2010 16:02:08 -0500 Benjamin Peterson <benjamin at python.org> wrote:

2010/10/31 Antoine Pitrou <solipsis at pitrou.net>: > On Sun, 31 Oct 2010 16:39:44 -0400 > Eric Smith <eric at trueblade.com> wrote: > >> What are your thoughts on adding a str.formatfrommapping (or similar >> name, maybe the suggested "formatmap") to 3.2? See >> http://bugs.python.org/issue6081 . This method would be similar to >> "%(foo)s %(bar)s" % d, where d is a dict (or rather any mapping object), >> but of course would use str.format syntax: "{foo} >> {bar}".formatfrommapping(d). > > I must be missing something, but what's the difference with > XXX.format(**d)?

It allows arbitrary mappings.

Ah, yes, sorry. I should have read the issue before posting. It's a bit embarassing to add a method for that, though, while formatting regular dicts doesn't need it.

Regards

Antoine.



More information about the Python-Dev mailing list