string formatting with mapping & '*'... is this a bug?

Pierre Fortin pfortin at pfortin.com
Fri Sep 10 00:06:43 EDT 2004


On 10 Sep 2004 00:42:19 GMT Bengt wrote:

> >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.

This must be one of those days when my density goes up.... :^/

Can you fill in the blanks on this...?  Mismatched quotes aside, I just
don't seem to grok how map's key gets in there since there is a ")"
between the format string and "%" -- then, I still don't see how "*.*"
gets set as it would in: "%*.*f" % (width,max,float)

I'll try to finally get a handle on subclassing/overriding with this.... 
:>

Pierre



More information about the Python-list mailing list