string formatting with mapping & '*'... is this a bug?
Bengt Richter
bokr at oz.net
Thu Sep 9 20:42:19 EDT 2004
On Thu, 9 Sep 2004 18:37:05 -0400, Pierre Fortin <pfortin at pfortin.com> wrote:
>On Fri, 10 Sep 2004 00:20:24 +0200 Alex wrote:
>
>> Diez B. Roggisch <deetsNOSPAM at web.de> wrote:
>> ...
>> > map2 = dict(map.items() + [(str(i), v) for i, v in enumerate(vals)])
>>
>> An equivalent ctor call that's slightly better, IMHO:
>>
>> map2 = dict([ (str(i),v) for i,v in enumerate(vals) ], **map)
>>
>> Don't ignore the power of dict's keyword arguments...
>>
>> > Not perfect, but IMHO better than your eval-based solution.
>>
>> I agree, mine is just a tiny improvement on your post, IMHO.
>>
>>
>> Alex
>
>Thanks for that; but it's not what I wanted... (see original post)
>
>I was hoping to use the likes of: "%(key)*.*f" % map
>however, unlike with the non-(key) formats, there appears to be no way to
>specify a "*.*" size when a map is used...
>
Well, you could subclass str and override its __mod__ method ;-)
If you had class format(str): ..., you could then write
format('%(key)*.*f") % map
and have it do whatever you like.
Regards,
Bengt Richter
More information about the Python-list
mailing list