3 ms·
Python's string format is also very similar to the "double mustache" convention widely used in web development. The following template string: "I have {{ap
by olooney 7y ago
Python's string format is also very similar to the "double mustache" convention widely used in web development. The following template string:
"I have {{apples}} apples"
To my certain knowledge this works in Jinja2, Django templates, Vue.js, mustache.js, handlebars.js, and probably many others.
PEP 498 mentions that they did look at other languages to see what was supported:
https://www.python.org/dev/peps/pep-0498/#similar-support-in-other-languages https://www.python.org/dev/peps/pep-0498/#similar-support-in...
And they link to this Wikipedia article, which lists many examples:
https://en.wikipedia.org/wiki/String_interpolation https://en.wikipedia.org/wiki/String_interpolation
Scanning through that, my impression is that "there is nothing new under the sun" and aside from an occasional "$" or "#" prefix, or a willfully arbitrary deviation like ColdFusion, the conventions can all be traced the Bourne shell /bin/sh/ which was released in 1979. Prior to that, the prinf() syntax was presumably the most common, but it's obscure.
Does anyone know if the ${variable} convention was original with the Bourne shell, or if it can be traced back further?
- fanf2 7y agoI am surprised to find that the 6th edition shell had only $1 etc positional parameter expansion, and named shell variables are not described in its man page http://man.cat-v.org/unix-6th/1/sh http://man.cat-v.org/unix-6th/1/sh