分享一个简单的python模板引擎
#coding:utf-
8
__author__="sdm"
__author_email='sdmzhu3@gmail.com'
__date__ ="$2009-8-25 21:04:13$"
''
'
pytpl 类似
php的模板类
''
'
import
sys
import
StringIO
import
os.path
import
os
#模
板的缓存
_tpl_cache={}
class
Pytpl:
def __init__(self,tpl_path='./'
):
self.tpl_path=tpl_path
self.data={}
self.output = StringIO.StringIO()
pass
def set(self,name,value):
''
'
设
置模板变量
''
'
self.data[name]=value;
pass
def get(self,name):
''
'
得
到模板变量
''
'
t={}
return
t.get(name,
''
)
pass
def tpl(self,tplname):
相关文档:
>>> import time
>>> import datetime
>>>
now = time.localtime()
>>> now
(2006, 4, 30, 18, 7, 35,
6, 120, 0)
>>> type(now)
<type 'time.struct_time'>
>>>
str_now = time.strftime("%m/%d/%Y %X", now )
>>>
str_n ......
os模块提供了多数操作系统的功能接口函数.当os模块被导入后,它会自适应于不同的操作系统平台,如posix或NT系统平台,os模块会根据不同的平台进行相应的操作.本节内容将对os模块提供的函数进行详细的解读.
1.1 文件操作函数
1.1.1 open()函数提供创建、打开、修改文件的功能。
Example 1-1. Using the os Module to Rename ......
Python与Mysql
一、安装MySQLdb模块
使用python连接Mysql的前提,就是需要一个让python连接到Mysql的接口,这就是MySQLdb模块。
验证是否已经安装了MySQLdb:
==========================================================
d:\usr\local\Python25>python
Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v ......