python decorator
1.³£Ó÷½·¨£¬²»´ø²ÎÊý
def decator(func):
def inner_func(*args):
args = (i * 2 for i in args)
return func(*args)
return inner_func
@decator
def add(a, b, c):
return a + b + c
2.´ø²ÎÊý£º
class Dec(object):
def __init__(self, i):
self.i = i
def __call__(self, func):
def inner_func(a, b, c):
return self.i * func(a, b, c)
return inner_func
@Dec(2)
def abc(x, y, z):
print "function abc"
print (x, y, z)
return x + y + z
Ïà¹ØÎĵµ£º
Posted on 18:40:00 by ÏþÔÂ and filed under Notepad++, Python
¡¡¡¡Notepad++ ÊÇÒ»¸ö¿ªÔ´µÄÎı¾±à¼Æ÷£¬¹¦ÄÜÇ¿´ó¶øÇÒʹÓ÷½±ã¡£±à¼ºÍµ÷ÊÔ Python ³ÌÐòʹÓÃʲô±à¼Æ÷»òÕß IDE ²»Í¬ÈËÓв»Í¬¼û½â¡£ÔÚ²»¿¼ÂÇʹÓõ÷ÊÔ¹¤¾ßµÄÇé¿öÏ£¬Vim »òÕß Emacs Óû§×ÔÈ»¿ÉÒÔÎÞÊÓÆäËû±à¼Æ÷£¬²»¹ýÔÚ Windows »·¾³Ï£¬Ê¹Óà Notepad++ Ö ......
¶ÔÊý¾Ý¿âµÄ²Ù×÷»ù±¾·ÖΪÈý²½£º
Á¬½ÓÊý¾Ý¿â
¸ù¾ÝÐèÒªÖ´ÐÐSQLÓï¾ä£¬½ÓÊÜ·µ»ØÖµ
¹Ø±ÕÁ¬½Ó
ÎÒÃÇÕý³£µÄÊý¾Ý¿âÓ¦¸Ã¶¼Àë²»¿ªÕâÈý²½£¬ÏÂÀ´ËµËµÈçºÎʹÓÃpythonÖеÄMySQLdbÄ£¿é½øÐÐÕâЩ²Ù×÷£º
Ê×ÏÈ£¬ÎÒÃÇÐèÒª°ÑMySQLdbÒýÈëµ½³ÌÐòÖÐ
import MySQLdb
È»ºó¿ªÊ¼Êý¾Ý¿â²Ù×÷
1.Êý¾Ý¿âÁ¬½Ó
conn = MySQLdb. ......
8.8. queue — A synchronized queue class¶
queue -- Ò»¸öͬ²½¶ÓÁÐÀà
The queue module implements multi-producer, multi-consumer queues. It is especially useful in threaded programming when information must be exchanged safely between multiple threads. The Queue class in this module implemen ......
дÁ˼¸¸öÓйØoperaminimodµÄpythonС³ÌÐò
firefox->opmÊéǩת»»
import re
def pipeiwangzhi(a):
s=[]
pp= re.compile(r'<DT><A HREF="(.*)" ADD_DATE=(.*>)(.*)</A>')
m=pp.search(a)
s1=[]
  ......
ÕâÊÇÒ»¸ö¼òµ¥µÄ±í´ïʽ¼ÆËãÆ÷, ²»Ì«¶®ÓÃTkinterдGUI, ²Î¿¼Á˱ðÈ˵ĴúÂë
from __future__ import division
from Tkinter import Tk, Entry, Button, Label, mainloop
from tkFont import Font
def get_value ():
v = ''
try:
v = eval(text.get()) #use eval to calculate the vlaue of the text
except:
pa ......