[Python-ideas] One way to do format and print

Brendan Barnwell brenbarn at brenbarn.net
Thu Sep 10 04:07:05 CEST 2015

On 2015-09-09 14:50, Andrew Barnert via Python-ideas wrote:
> Well, have you read the answers given by Nick, me, and others earlier
> in the thread? If so, what do you disagree with? You've only
> addressed one point (that % is faster than {} for simple cases--and
> your solution is just "make {} faster", which may not be possible
> given that it's inherently more hookable than % and therefore
> requires more function calls...). What about formatting headers for
> ASCII wire protocols, sharing tables of format strings between
> programming languages (e.g., for i18n), or any of the other reasons
> people have brought up?

	This getting off on a tangent, but I don't see most of those as super 
compelling.  Any programming language can use whatever formatting scheme 
it likes.  Keeping %-substitutions around helps in sharing format 
strings only with other languages that use exactly the same formatting 
style.  So it's not like % has any intrinsic gain; it just happens to 
interoperate with some other particular stuff.  That's nice, but I don't 
think it makes sense to keep things in Python just so it can 
interoperate in specific ways with specific other languages that use 
less-readable syntax.

	To me the main advantage of {} is it's more readable.  Readability is 
relevant in any application.  The other things you're mentioning seem to 
be basically about making certain particular applications easier, and I 
see that as less important.  In other words, if to write a wire protocol 
or share format strings you have to write your own functions to do stuff 
in a more roundabout way instead of using a (or the!) built-in 
formatting mechanism, I'm fine with that if it streamlines the built-in 
formatting mechanism(s).

	(The main DISadvantage of {} so far is that its readability is limited 
because you have to pass in all that stuff with the format call at the 
end.  I think if one of these string-interpolation PEPs settles down and 
we get something like "I like {this} and {that}" --- where the names are 
drawn directly from the enclosing scope without having to pass them in 
--- that will be a huge win over both the existing {} formatting and the 
% formatting.)

Brendan Barnwell
"Do not follow where the path may lead.  Go, instead, where there is no
path, and leave a trail."
    --author unknown

More information about the Python-ideas mailing list