Вы можете использовать стандартную библиотеку шаблон строки :
Итак, у вас есть файл foo.txt
с
$title
...
$subtitle
...
$list
и словарь
d={ 'title':title, 'subtitle':subtitle, 'list':'\n'.join(list) }
Тогда это довольно просто
from string import Template
#open the file
filein = open( 'foo.txt' )
#read it
src = Template( filein.read() )
#do the substitution
src.substitute(d)
Тогда вы можете напечатать src
Конечно, как сказал Jammon, у вас есть много других хороших шаблонизаторов (это зависит от того, что вы хотите сделать ... стандартный шаблон строки, вероятно, самый простой)
Полный рабочий пример
foo.txt
$title
...
$subtitle
...
$list
example.py
from string import Template
#open the file
filein = open( 'foo.txt' )
#read it
src = Template( filein.read() )
#document data
title = "This is the title"
subtitle = "And this is the subtitle"
list = ['first', 'second', 'third']
d={ 'title':title, 'subtitle':subtitle, 'list':'\n'.join(list) }
#do the substitution
result = src.substitute(d)
print result
Затем запустите example.py
$ python example.py
This is the title
...
And this is the subtitle
...
first
second
third