¹ØÓÚPythonÖÐÒ»Öֻص÷·½Ê½µÄʵÏÖ
#¹ØÓڻص÷¹¦ÄܵIJâÊÔ
#FunctorÊÇÕâÖֻص÷¹¦ÄܵĹؼü¶ÔÏó
class Functor:
"""Simple functor class."""
def __init__( self, fn, *args ):
self.fn = fn
self.args = args
def __call__( self, *args ):
self.fn( *(self.args + args) )
#Ïë¶Ô¸Ãº¯Êý½øÐлص÷²Ù×÷
def test_callback1(arg1, arg2):
print "test_callback1", arg1, arg2
#ÏȽøÐмòµ¥µØ²âÊÔ
obj_call1 = Functor(test_callback1, 1111, 'qweqwe111111111')
obj_call1()
#½á¹û£º
#test_callback1 1111 qweqwe111111111
#¿´¿´¹ý³ÌÖдøÈë²ÎÊýµÄ·½Ê½
def test_callback2(arg1, arg2, call_arg):
print "test_callback2", arg1, arg2, call_arg
obj_call2 = Functor(test_callback2, 2222, 'qweqwe22222222')
obj_call2(222)#¹ý³ÌÖÐÊäÈë²ÎÊý£¬²¢ÇÒʹ»Øµ÷º¯ÊýµÃµ½Õâ¸ö²ÎÊý
#½á¹û£º
#test_callback2 2222 qweqwe22222222 222
#ÔÙÀ´¿´¿´¶ÔÏóÖеķ½·¨±»ÓÃÀ´»Øµ÷
#»ù±¾ÔÀíÓëÉÏÃæÁ½¸öÀý×ÓÏàͬ£¬µ«¿ÉÒÔÒýÈë¶ÔÏó±¾ÉíµÄº¯Êý
#²¢ÇÒÒ²¿ÉÒýÈëÆäËû¶ÔÏó½øÐлص÷£¬ÄÇôËüµÄÓ÷¨½«»á·Ç³£·á¸»
class Test:
def __init__(self):
pass
def test_callback1(self, arg1, arg2):
print "Test.test_callback 1111", arg1, arg2
def test_callback2(self, arg1, arg2, call_arg):
print "Test.test_callback 2222", arg1, arg2, call_arg
def test_callback_arg(self):
obj_call1 = Functor(self.test_callback1, 1111, 'qweqwe1111')
print "obj_call1 = ",obj_call1
 
Ïà¹ØÎĵµ£º
µ±ÒªÊ¹º¯Êý½ÓÊÕÔª×é»ò×ÖµäÐÎʽµÄ²ÎÊýµÄʱºò£¬ÓÐÒ»ÖÖÌØÊâµÄ·½·¨£¬Ëü·Ö±ðʹÓÃ*ºÍ**ǰ׺¡£ÕâÖÖ·½·¨ÔÚº¯ÊýÐèÒª»ñÈ¡¿É±äÊýÁ¿µÄ²ÎÊýµÄʱºòÌØ±ðÓÐÓá£
>>> def powersum(power, *args):
... '''Return the sum of each argument raised to specified power.'''
... ......
Éè¼ÆÄ£Ê½ÊÇÒ»¸ö³éÏó²ã´Î£¬ÃèÊöÁËÔÚÒ»¸öÌØ¶¨µÄ»·¾³ÖÐÓÃÀ´½â¾öÒ»°ãÉè¼ÆÎÊÌâµÄ¶ÔÏóºÍÀàÖ®¼äµÄ½»»¥¹ØÏµ£¬ÆäÖ÷ҪĿµÄÊdzä·ÖÀûÓÃÓïÑÔµÄÌØÐÔ£¬Éè¼Æ¿É¸´Óõġ¢Äܹ»ÊÊÓ¦ÐèÇó±ä¸üµÄÈí¼þ[9]¡£Éè¼ÆÄ£Ê½ÊÇÒ»ÖÖÉè¼ÆË¼Ï룬ÓïÑÔÊÇʵÏÖ˼ÏëµÄ¹¤¾ß¡£Òò´Ë£¬²»Í¬ÓïÑÔµÄÌØÐÔÓ°ÏìÁËÉè¼ÆÄ£Ê½µÄʵÏÖ£¬ÓÐЩÓïÑÔ¸üÈÝÒ×ʵÏÖÉè¼ÆÄ£Ê½£¬¶øÓÐЩÓïÑÔÔ ......
ÔÎÄ
http://www.hetland.org/python/instant-hacking.php
Instant Hacking[Òë
ÎÄ]
ÒëÕߣº ¿Ï¶¨À´¹ý   ......
ÓõķֱðÊÇtimeºÍdatetimeº¯Êý
'''
Created on 2009-9-2
@author: jiangqh
'''
import time,datetime
# date to str
print time.strftime("%Y-%m-%d %X", time.localtime())
#str to date
t = time.strptime("2009 - 08 - 08", "%Y - %m - %d")
y,m,d = t[0:3]
print datetime.datetime(y,m,d)
Êä³öµ±Ç°Ê±¼ä ......
Ê×ÏÈ, ˵˵pythonÀïÃæµÄ±Õ°ü°É:
1. ÐèÒªº¯ÊýǶÌ×, ¾ÍÊÇÒ»¸öº¯ÊýÀïÃæÔÙдһ¸öº¯Êý.
2. Íⲿº¯ÊýÐèÒª·µ»ØÒ»¸öÄÚ²¿º¯ÊýµÄÒýÓÃ
3. Íⲿº¯ÊýÖÐÓÐһЩ¾Ö²¿±äÁ¿, ²¢ÇÒ, ÕâЩ¾Ö²¿±äÁ¿ÔÚÄÚ²¿º¯ÊýÖÐÓÐʹÓÃ
¸ÅÄî:
1. ×ÔÓɱäÁ¿: Íⲿº¯ÊýÖж¨ÒåµÄ¾Ö²¿±äÁ¿, ²¢ÇÒÔÚÄÚ²¿º¯ÊýÖб»Ê¹ÓÃ.
2. ±Õ°ü: ÄǸöʹÓÃÁË×ÔÓɱäÁ¿²¢±»·µ»ØµÄÄÚ²¿º¯Ê ......