A recent post by Terry Jan Reedy got me thinking about formatting.  I
like the new(ish) format method for strings and I see some value in F
strings but it only works well with locals.  Anything more starts
getting messier than format() and it is supposed to be cleaner.  Also, I
find that I tend to re-use format strings and wish there was a
formatting string option.  Here is what I came up with.

class FSTR(str):
  def __call__(self, *args):
    return self.format(*args)

And here is how it could be used.

s = FSTR("ABC {1} {0} {2[x]}")
...
print(s(1, 2, dict(x=3)))

Too bad that it is too late to assign f'' to that function.

-- 
D'Arcy J.M. Cain
Vybe Networks Inc.
http://www.VybeNetworks.com/
IM:da...@vex.net VoIP: sip:da...@vybenetworks.com
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to