Create file by template
$title
...
$subtitle
...
$list
from string import Template
#open the file
file = open( 'foo.txt' )
#read it
template = Template( file.read() )
#document data
title = "This is the title"
subtitle = "And this is the subtitle"
list = ['first', 'second', 'third']
file_content={ 'title':title, 'subtitle':subtitle, 'list':'\n'.join(list) }
#do the substitution
result = template.substitute(file_content)
print result