Python Mako Template ѧϰ±Ê¼Ç
MakoÊÇʲô£¿MokoÊÇPythonдµÄÒ»¸öÄ£°å¿â£¬Python¹ÙÍøpython.orgÓõľÍÊÇËüŶ¡£ÆäËû·Ï»°Ò²¾Í²»ÀÛ׸ÁË£¬Ö±½ÓÀ´µã´úÂ룬·½±ãÔĶÁÓëÁ˽â°Ñ¡£
(Mako¹ÙÍøµØÖ·£ºhttp://www.makotemplates.org/ £¬¿ÉÒÔÏÂÔØ°²×°°ü£¬ÍƼöʹÓÃeasy_install°²×°)
from mako.template import Template
mytemplate = Template("hello world!")
print mytemplate.render()
mytemplate = Template("hello, ${name}!")
print mytemplate.render(name="jack")
´úÂë¿ÉÒԲο¼¹Ù·½doc²¿·Ö
mytemplate = Template(filename='/docs/mytmpl.txt')
print mytemplate.render()
»¹¿ÉÒÔ´ÓÉèÖÃÄ£°åΪÎļþ£¬ÉèÖÃfilenameÊôÐÔ
mytemplate = Template(filename='/docs/mytmpl.txt', module_directory='/tmp/mako_modules')
print mytemplate.render()
Îļþ»¹¿ÉÒÔ»º´æµ½Ä³¸öĿ¼Ï£¬ÏÂÃæµÄ/docs/mytmpl.txt»á²úÉúÒ»¸öpy£º/tmp/mako_modules/docs/mytmpl.txt.py
from mako.lookup import TemplateLookup
mylookup = TemplateLookup(directories=['/docs'])
mytemplate = Template("""<%include file="header.txt"/> hello world!""", lookup=mylookup)
²éÕÒÄ£°å£¬·½±ãͳһģ°å·¾¶Ê¹Óá£
mylookup = TemplateLookup(directories=['/docs'], module_directory='/tmp/mako_modules')
def serve_template(templatename, **kwargs):
mytemplate = mylookup.get_template(templatename)
print mytemplate.render(**kwargs)
¸ÄÁ¼ÁËÉÏÃæµÄ²éÕÒ·½Ê½
mylookup = TemplateLookup(directories=['/docs'], output_encoding='utf-8',
encoding_errors='replace')
mytemplate = mylookup.get_template("foo.txt")
print mytemplate.render()
ÉèÖÃÊä³ö±àÂ룬ÒÔ¼°±àÂë´íÎóʱºò´¦Àí·½Ê½
.
À´Ô´:"СÓ㲩¿Í" http://chenxiaoyu.org/blog/
Ïà¹ØÎĵµ£º
1£¬²»ÓÃÐÞ¸Ä/etc/vimϵÄvimrc¼°gvimrcÎļþ ¡£¡£¡£
2£¬ÔÚ~Ŀ¼Ï£¬Ð½¨Ò»¸ö.vimrcµÄÅäÖÃÎļþ¡£ÄÚÈÝÈçÏ£º£¨¸ßÁÁ£¬×Ô¶¯¶ÔÆë£¬×Ô¶¯Ëõ½ø£¬ÏÔʾÐкţ©
" An example for a vimrc file.
"
" Maintainer: Bram Moolenaar <Bram@vim.org>
" Last change: 2006 Nov ......
while µÄÓ÷¨£º
while ºóÃæ¸úÌõ¼þ±í´ïʽ£¬(:)ºóÃæ¸úÓï¾ä¿é£¬Äã¿ÉÒÔÔÚÕâ¶ÎÓï¾ä¿éÀïÐÞ¸ÄÌõ¼þ±í´ïʽµÄijЩ±äÁ¿£¬µ±Ìõ¼þ±í´ïʽ Ϊ¼ÙµÄʱºòÍ˳öÑ»·¡£ÀýÈ磺
flag = 5
while flag > 0:
#ÕâÀïÊÇÄãµÄ´úÂë
flag -= 1
#if flag == 3: break
#if flag == 3: continue
print flag
µ±È»ÄãÒ²¿ÉÒÔÔÚÊʵ ......
ÔÎijö´¦£ºhttp://www.amk.ca/python/howto/regex/
ÔÎÄ×÷ÕߣºA.M. Kuchling £¨amk@amk.ca£©
ÊÚȨÐí¿É£º´´×÷¹²ÏíÐÒé
·ÒëÈËÔ±£ºFireHare
У¶ÔÈËÔ±£ºLeal
ÊÊÓð汾£ºPython 1.5 ¼°ºóÐø°æ±¾
¼ò½é
Python ×Ô1.5°æ±¾ÆðÔö¼ÓÁËre Ä£¿é£¬ËüÌṩ Perl ·ç¸ñµÄÕýÔò±í´ïʽģʽ¡£Python 1.5֮ǰ°æ±¾ÔòÊÇͨ¹ý regex
Ä£¿éÌṩ ......
½ñÌìѧϰÁËÒ»ÏÂPythonµÄ²Ù×÷·ûÖØÔØ£¬×ܽáÁ˼¸µã±È½ÏÉñÆæµÄ¶«¶«£º
------------------------------------------------------------------------------------------------------------
¹ØÓÚiter£º
Technically, iteration contexts work by calling the iter built-in function to try to
find an _ _iter_ _ method, whi ......