# -*- coding: utf-8 -*-
import string
values = {'var' : 'foo'}
tem = string.Template('''''
Variable : $var
Escape : $$
Variable in text : ${var}iable
''')
print 'TEMPLATE:', tem.substitute(values)
str = '''''
Variable : %(var)s
Escape : %%
Variable in text : %(var)siable
'''
print 'INTERPOLATION:', str%values
TEMPLATE: Variable : foo Escape : $ Variable in text : fooiable INTERPOLATION: Variable : foo Escape : % Variable in text : fooiable
# -*- coding: utf-8 -*-
import re
my_str = "(condition1) and --condition2--"
print my_str.replace("condition1", "").replace("condition2", "text")
rep = {"condition1": "", "condition2": "text"}
rep = dict((re.escape(k), v) for k, v in rep.iteritems())
pattern = re.compile("|".join(rep.keys()))
my_str = pattern.sub(lambda m: rep[re.escape(m.group(0))], my_str)
print my_str
() and --text-- () and --text--
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有