Re:Python Extension Proposal 498: Literal String Formatting
by chrismorgan on Wednesday August 26, 2015 @04:04AM
(#10121706)
It would also render the previous ways obsolete. New-style formatting never took over completely from old-style because it wasn’t sufficiently compelling—`"%s %s" % (a, b)` versus `"{} {}".format(a, b)` doesn’t have a clear winner. But `f"{a} {b}"`? Clearly superior. With the exception of backwards compatibility matters (which will be a nuisance for far too long), there would really be no reason to keep using the old ways in most places. i18n/l10n would really be the only mainstream reason for using anything other than f-strings.
[ Parent
| on HN ]
Re:Python Extension Proposal 498: Literal String Formatting
by voyou on Wednesday August 26, 2015 @04:46AM
(#10121807)
"It would also render the previous ways obsolete."
I don't think it would. If I understand this PEP correctly, the "format" method is significantly more dynamic. For instance, I don't think this new PEP would allow for cases where the template isn't stored directly in the program, or where the values to interpolate are not local variables. So you would still need to keep str.format around for those use cases.
Re:Python Extension Proposal 498: Literal String Formatting
by wylee on Wednesday August 26, 2015 @12:15PM
(#10123957)
Your example isn't very compelling, but for longer strings with more complex formatting, I'd say .format() is pretty compelling. I find that in general
'{x} blah blah blah {y}'.format(x=x, y=y)
is more readable than '%s blah blah blah %s' % (x, y)
even if the former is a bit longer.On top of that, there's a whole bunch of stuff you can do with .format() that just isn't possible with %.
Re:Python Extension Proposal 498: Literal String Formatting
by cnvogel on Thursday August 27, 2015 @02:40AM
(#10127896)
Even .format() is quite redundant for the "standard" usage, as we had string interpolation using '%' with dicts for a long time.
'%s blah blah blah %s' % (x, y)
'{x} blah blah blah {y}'.format(x=x, y=y)
'%(x)s blah blah blah %(y)s'%{'y':y, 'x':x}