Draft PEP: string interpolation with backquotes

Oren Tirosh oren-py-l at hishome.net
Tue Dec 4 02:16:39 EST 2001


On Tue, Dec 04, 2001 at 10:07:41AM +1100, Richard Jones wrote:
> This would then cause confusion - why not revert back to using $ as the magic 
> interpolation character? It has no prior history in Python and therefore no 
> preconceived ideas exist as to what its result might be. It does have some 
> history outside of Python as a string interpolation character though, in 
> many, many systems...

This proposed form of interpolation is fundamentally different from that found
in scripting languages and I believe it deserves a syntax that highlights
this difference.  The embedded expression is NOT part of the string.  It is 
a real Python expression, syntax-checked at compile time and converted into 
bytecode.  No parsing, escaping or quoting is done at runtime.

Your language-aware editor should even color-code it as it would any other
expression, not with the color code for a string.  Syntactically, the string 
starts at the quotes and ends at the backtick and another string starts at 
the backtick and ends at the quotes.  The expression is surrounded by string 
fragments with unbalanced quoting.

As for the issue of interpolation with backticks being equivalent to str()
rather than repr() - I believe most people won't even notice.  When the
system simply does the Right Thing according to the context it feels more
consistent even if technically it isn't.

Please read my previous posting titled 'On string formatting and functional
programming'.

	Oren





More information about the Python-list mailing list