PythonÖ®ÃÀ DecoratorÉîÈëÏê½â(Ò»)
There should be one—--and preferably only one –--obvious way to do it.
----Õª×ÔThe Zen of Python, by Time Peters
һЩÍùÊÂ
ÔÚÕýʽ½øÈëDecorator»°Ìâ֮ǰ£¬ÇëÔÊÐíÎÒ½²Ò»¸öС¹ÊÊ¡£
ÔÚ×î½üµÄÏîÄ¿¿ª·¢¹ý³ÌÖУ¬Ò»Î»Í¬ÊÂÔÚ¶ÁÎҵĴúÂëµÄʱºò£¬Ìá³öÖÊÒÉ£¬ÎªÊ²Ã´Í¬ÑùµÄÑéÖ¤´úÂëÒªÖظ´³öÏÖÔÚ·þÎñ½Ó¿ÚÖÐÄØ£¿
Èçij·þÎñ½Ó¿ÚÊÇÓÎÏ·ÖеÄÍæ¼ÒÏ뽨Ô콨Öþ£º
def build(user, build_name):
if not is_user_valid(user):
redirect("/auth/login/")
return False
#do something here
return create_building(build_name)
ÔÚbuildÕâ¸ö·½·¨ÖУ¬Ç°3ÐÐÊÇÓÃÀ´¼ì²âÍæ¼ÒÊÇ·ñÒѾÑéÖ¤¹ýµÄ£¬Èç¹ûÊÇ·ÇÑéÖ¤µÄÍæ¼Ò£¬¾ÍÖض¨Ïòµ½µÇ½ҳÃ棻Èç¹ûÊÇÑéÖ¤¹ýµÄÍæ¼Ò£¬¾Í¸øËû½¨ÔìËûÏëÒªµÄ½¨Öþ¡£
ËûÖ¸³öÕâÑùµÄ3ÐÐÑéÖ¤´úÂë(ËäÈ»ÒѾºÜ¶Ì)½«»á³öÏÖÈÎÒâÒ»¸öÍæ¼Ò·þÎñ½Ó¿ÚÖЗ—Éý¼¶½¨Öþ¡¢²ð½¨Öþ¡¢ÉõÖÁÊÇƵ·±µÄÁÄÌ죬ÎÒ˵ÕâÖ»ÊÇCtrl+C¡¢Ctrl+VµÄʱ¼ä°¡£¬µ«ÊÇÄÇʱºòÎÒÉîÏ룬Èç¹ûÏÖÔÚÐèÇóÓб䶯£¬ÒªÔÚÔÀ´µÄÑé֤ʧ°ÜµÄÇé¿öÏ£¬Ð´ÈÕÖ¾£¬ÄÇÔÀ´µÄ3ÐдúÂë¾Í±ä³É4ÐУº
if not is_user_valid(user):
redirect("/auth/login/")
log_warning(" %s is trying to enter without permission!" %(user["name"]))
return False
¸üÍ´¿àµÄÊÇ£¬ÄãÒªÔÚÿ¸ö³öÏÖif not is_u
Ïà¹ØÎĵµ£º
http://www.autohotkey.com/forum/topic53773.html
Q:I am searching for is a way to execute AHK commands from a Python script. Is this possible?
A:Yes. Here is an example.
tested with python2.6, requires AutoHotkey.dll in the working directory or path...
ahkpython.py:
#Persistent
dllc ......
ÆäʵÒì³£¾ÍÊDz»Õý³££¬¾ÍÊDz»ºÍÎÒÃÇÏëÏóÒ»ÑùÈ¥Ö´ÐС£ËüÊÇÒòΪ³ÌÐò³öÏÖÁË´íÎó¶øÔÚÕý³£¿ØÖÆÁ÷ÒÔÍâ²ÉÈ¡µÄÐÐΪ¡£Python³öÏÖÒì³££¬¾ÍÊÇÒòΪ¼ì²éÁËÒ»¸ö´íÎóʱ£¬Python½âÊÍÆ÷ÎÞ·¨¼ÌÐø¼ÌÐøÖ´ÐÐÏÂÈ¥£¬ÕâʱºòÅ׳öÁËÒì³£¡£ÍùÍùÕâ¸ö´íÎó·ÖΪÓï·¨ÉϺÍÂß¼ÉÏ(²»Éó¤Ëµ¸ÅÄ-_-! )£¬¿´¿´¼¸¸öÀý×Ó£¬×ܽáһϣº
1¡¢NameError£º³¢ÊÔ·ÃÎÊÒ»¸öÎ ......
RubyºÍPythonµÄÓï·¨±È½Ï
ÆäʵRubyºÍPython·Ç³£½Ó½ü£¬±È´ó¶àÊý±ðµÄÓïÑÔÒª½Ó½üµÄ¶à£¬ËùÒÔϲ»¶ÓÃɶ¾ÍÓÃɶ£¨´óʵ»°£¬ËäȻҲÊÇ·Ï»°£©¡£Óï·¨ÉϵIJî±ðËäÈ»ÓÐÄÇôһµã£¬´ó²¿·ÖÊÇsyntax sugar£¬ÎÒ¶·µ¨ÉÔ΢Áм¸¸ö£¨pythonÎÒÒ²ÍüµÃ²î²»¶àÁË£¬²»¶ÔµÄ´ó¼Ò¾¡¹ÜÀ´±Þʬ°É£©£¬µ«ÊÇÖ÷Òª²îÒ컹ÊÇÉè¼Æ˼ÏëÉϵģºÁé»î ......
conn = httplib.HTTPConnection(EPG_IP + ":" + HTTP_PORT)
url = FAV_URL_PARTH +"userid=" + USER_ID + FAV_DIR_MODIFY
param = '''<ps100request id="Favorite.Category.modify">
<categoryid>'''+categoryid+'''</categoryid>
<categoryname>'''+categoryname+'''</ ......
import win32com.client
store = win32com.client.Dispatch('CAPICOM.Store')
# ´ò¿ªÖ¤Êé´æ´¢Çø
# 2 -> CAPICOM_CURRENT_USER_STORE
# 0 -> CAPICOM_STORE_OPEN_READ_ONLY
store.Open(2, "My", 0)
# ²éÕÒÓÐЧ֤Êé
# 12 -> CAPICOM_CERTIFICATE_FIND_KEY_USAGE
# 0x00000080 -> CAPICOM_DIGITAL_SIGNATU ......