Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

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/


Ïà¹ØÎĵµ£º

python Ö® pilÉú³ÉÑéÖ¤ÂëͼƬ

#!/usr/bin/python
#coding=utf-8
import Image,ImageDraw,ImageFont,os,string,random,ImageFilter
def initChars():
"""
ÔÊÐíµÄ×Ö·û¼¯ºÏ£¬³õʼ¼¯ºÏΪÊý×Ö¡¢´óСд×Öĸ
usage: initChars()
param: None
return: list
·µ»ØÔÊÐíµÄ×Ö·û¼¯ºÍ
for: picCheckerÀà³õʼ×Ö·û¼¯ºÏ
todo: ......

Python³õѧ±Ê¼Ç£¨×ªÔØ£©


while µÄÓ÷¨£º
while ºóÃæ¸úÌõ¼þ±í´ïʽ£¬(:)ºóÃæ¸úÓï¾ä¿é£¬Äã¿ÉÒÔÔÚÕâ¶ÎÓï¾ä¿éÀïÐÞ¸ÄÌõ¼þ±í´ïʽµÄijЩ±äÁ¿£¬µ±Ìõ¼þ±í´ïʽ Ϊ¼ÙµÄʱºòÍ˳öÑ­»·¡£ÀýÈ磺
flag = 5
while flag > 0:
#ÕâÀïÊÇÄãµÄ´úÂë
flag -= 1
#if flag == 3: break
#if flag == 3: continue
print flag
µ±È»ÄãÒ²¿ÉÒÔÔÚÊʵ ......

python random Ëæ»úµÄÎÊÌâ

ÔÚÒ»¸öÏîÄ¿ÖÐÐèÒª»ñÈ¡Ëæ»úÊý£¬Ë­ÖªµÀÓöµ½µãÎÊÌ⣺Ëæ»úÊý²»Ëæ»ú¡£ËùÒÔÎÒдÁ˸ö¼òµ¥Ô­ÐÍ¡£¿´Ïµ½µ×ÊÇɶÎÊÌâ¡£
import os,random,sys,time
while True:
father = os.fork()
if father:
time.sleep(2)
rd = 7
else:
#random.seed()
rd = random.choice([2,3,4,5])
......

windowsÏÂʹÓÃgccµ÷ÓÃpythonµÄÎÊÌâ

ÓÃgcc±àÒëÁËÒ»¸öC++µ÷ÓÃpythonµÄ³ÌÐò£¬Õâ¸ö³ÌÐòÔÚVSÏÂÊǺÃÓõģ¬¶øÇÒûÓÐʹÓÃvsµÄÈκοâ
¿ÉÊǵ½ÁËgccϾÍÊÇÎÞ·¨Ê¹ÓÃ
ºóÀ´ÉÏÍø²éÁËÒ»ÏÂ×ÊÁϲÅÖªµÀ£¬ÊÇÒòΪclÓëgccµÄÔËÐÐʱ¿â²»Í¬¡£
´ò¿ªcmd´°¿Ú£¬ÊäÈëpython¾Í¿ÉÒÔ¿´µ½
Python 3.0 (r30:67507, Dec  3 2008, 20:14:27) [MSC v.1500 32 bit (Intel)] on win32
Type " ......

Python »ù´¡2

8.PythonÖÐûÓÐswitchÓï¾ä,¿ÉÒÔÓÃif..elif..elseÓï¾äÍê³ÉͬÑùµÄ¹¤×÷(ijЩ³¡ºÏ,ʹÓÃ×Öµä»á¸ü¼Ó¿ì½Ý)
9.whileÓï¾ä°üº¬Ò»¸öelseµÄ´Ó¾ä.
10.rangeÏòÉÏÑÓÉìµ½µÚ¶þ¸öÊý,¼´Ëü²»°üº¬µÚ¶þ¸öÊý.
11.ʹÓÃglobalÓï¾ä¿ÉÒÔÇå³þµØ±íÃ÷±äÁ¿ÊÇÔÚÍâÃæµÄ¿é¶¨ÒåµÄ. ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ