分享一个简单的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):
相关文档:
%a 星期几的简写
%A 星期几的全称
%b 月分的简写
%B 月份的全称
%c 标准的日期的时间串
%C
年份的后两位数字
%d 十进制表示的每月的第几天
%D 月/天/年
%e 在两字符域中,十进制表示的每月的第几天
%F
年-月-日
%g 年份的后两位数字,使用基于周的年
%G 年分,使用基于周的年
%h 简写的月份名 ......
import types
type(x) is types.IntType # 判断是否int 类型
type(x) is types.StringType #是否string类型
.........
--------------------------------------------------------
超级恶心的模式,不用记住types.StringType
import types
type(x) == types(1) # ......
myDict = { 'item1' : [ 7, 1, 9], 'item2' : [8, 2, 3], 'item3' : [ 9, 3, 11 ] }
def sortDic(Dict,valuePostion):
return sorted(Dict.items(),key=lambda e:e[1][valuePostion])
//按value的第3个值排序
sortDic(myDict,2)
[('item2', [8, 2, 3]), ('item1', [7, 1, 9]), ('item3', [9, 3, 11])]
//按value的第 ......
初学Python,这么做好像有点2,凑合能用:
class MyClass():
def __init__(self, n = 10):
self._Field = n
def __getitem__(self, range):
return MyClass(self._Field)
obj1 = MyClass()
obj2 = obj1
obj3 = obj1[:]
obj1._Field = 100
obj4 = MyClass(123)
print obj1._Field, obj2. ......
这个类表示在单独的控制线程中运行的活动。有两种方法可以指定这种活动,给构造函数传递回调对象,或者在子类中重写run() 方法。其他方法(除了构造函数)都不应在子类中被重写。换句话说,在子类中只有__init__()和run()方法被重写。
一旦线程对象被创建,它的活动需要通过调用线程的start()方法来启动。这方法再调用控制 ......