python的cheetah小例子

从python in a nutshell 中摘抄小例子.
import Cheetah.Template
import os, time, socket

tt = Cheetah.Template.Template('''
<html><head><title>Report by $USER</title></head><body>
<h1>Report on host data</h1>
<p>Report written at $asctime:<br/>
#for $hostline in $uname
  $hostline<br/>
#end for
</p></body></html>
''', searchList=[time, os.environ])

try: 
    tt.uname = os.uname
except AttributeError:
    tt.uname = [socket.gethostname(  )]

print tt

你可能感兴趣的:(java,python,socket,OS)