Is there a native templating system for plain text files in Python?

There are quite a number of template engines for python: Jinja, Cheetah, Genshi etc. You won't make a mistake with any of them.


You can use the standard library string an its Template class.

Having a file foo.txt:

$title
$subtitle
$list

And the processing of the file (example.py):

from string import Template

d = {
    'title': 'This is the title',
    'subtitle': 'And this is the subtitle',
    'list': '\n'.join(['first', 'second', 'third'])
}

with open('foo.txt', 'r') as f:
    src = Template(f.read())
    result = src.substitute(d)
    print(result)

Then run it:

$ python example.py
This is the title
And this is the subtitle
first
second
third