2011-09-08 24 views

回答

1

下面是使用字符串模板解決方案:

#!/usr/bin/env python 

import string 

s=string.Template(""" 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 

     "http://www.w3.org/TR/html4/loose.dtd"> 
<html lang="en"> 
<head> 
    <meta http-equiv="content-type" content="text/html; charset=utf-8"> 
    <title>My page</title> 
</head> 
<body> 
<p>$text</p> 
</body> 
</html> 
""") 

s.substitute(text='Hello World') 

現在,輸出存入一個文件,然後在瀏覽器中打開...

對於較嚴重的發展,看看django