[Python-ideas] string.Template v2

anatoly techtonik techtonik at gmail.com
Thu Nov 28 17:57:42 CET 2013


http://docs.python.org/2/library/string.html#template-strings

## Original Idea

stdlib lacks the most popular basic variable extension syntax
"{{ variable }}" that can be found in Django [1], Jinja2 [2] and
other templating engines [3].

## stdlib Analysis

string.Template syntax is ancient (dates back to Python 2.4
from 9 years ago). I haven't seen a template like this for a long time.

## Scope of Enhancement

st = 'Hello {{world}}.'
world = 'is not enough'
t = Template(string, style='brace')
t.render(locals())

## Links

1. https://docs.djangoproject.com/en/dev/topics/templates/#variables
2. http://jinja.pocoo.org/docs/templates/#variables
3. http://mustache.github.io/

## Feature Creeping

# Allow to override {{ }} symbols to make it more generic.

# `foo.bar` attribute lookup for 2D (nested) structures.

Questions is it has to be supported:
  `foo.bar` in Django does dictionary lookup first, then attribute lookup
  `foo.bar` in Jinja2 does attribute lookup first

I am not sure which is better. I definitely don't want some method or
property on a dict passed to render() method to hide dict value.
--
anatoly t.


More information about the Python-ideas mailing list