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

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


Ïà¹ØÎĵµ£º

PythonÖеÄһЩÒì³£

ÆäʵÒì³£¾ÍÊDz»Õý³££¬¾ÍÊDz»ºÍÎÒÃÇÏëÏóÒ»ÑùÈ¥Ö´ÐС£ËüÊÇÒòΪ³ÌÐò³öÏÖÁË´íÎó¶øÔÚÕý³£¿ØÖÆÁ÷ÒÔÍâ²ÉÈ¡µÄÐÐΪ¡£Python³öÏÖÒì³££¬¾ÍÊÇÒòΪ¼ì²éÁËÒ»¸ö´íÎóʱ£¬Python½âÊÍÆ÷ÎÞ·¨¼ÌÐø¼ÌÐøÖ´ÐÐÏÂÈ¥£¬ÕâʱºòÅ׳öÁËÒì³£¡£ÍùÍùÕâ¸ö´íÎó·ÖΪÓï·¨ÉϺÍÂß¼­ÉÏ(²»Éó¤Ëµ¸ÅÄ-_-! )£¬¿´¿´¼¸¸öÀý×Ó£¬×ܽáһϣº
1¡¢NameError£º³¢ÊÔ·ÃÎÊÒ»¸öÎ ......

pythonдµÄ½«Ò»Ð©ÀàÐ͵ÄÎļþѹËõΪ7z¸ñʽ

#½«Ò»Ð©ÀàÐ͵ÄÎļþѹËõΪ7z.py
#for folder all file do 7z
import os
import sys
import distutils.file_util
def ImportOkFile():
    if(os.path.isfile("D:\\Records\\½«Ò»Ð©ÀàÐ͵ÄÎļþѹËõΪ7z_record.txt")==False):
        f=open("D:\\Reco ......

python ¶ÁhttpС¼Ç

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+'''</ ......

ÓÃpythonʵÏÖcrc32Çó×Ö·û´®Ð£ÑéÂë


תÌû£º
http://blog.csdn.net/wyingquan/archive/2008/12/20/3561094.aspx
ÓÃpython×Ô´øµÄbinasciiÄ£¿é¼ÆËã×Ö·û´®µÄУÑéÂ룬³öÀ´µÄÊǸºÖµ£¬ÓëÓÃcдµÄ³ÌÐòµÃ³öµÄУÑéÂë²»Ò»Ñù£¬ËùÒÔ¾ÍÑо¿ÁËһϡ£·¢ÏÖ±ðÈËÓõÄpython3.0°æ±¾binasciiÄ£¿é¼ÆËã³öµÄcrc32УÑéÂëÊÇÎÒÏëÒªµÄ£¬Ã»°ì·¨Ö»ºÃ×Ô¼ºÓÃpythonʵÏÖÒ»ÏÂcrc32µÄËã·¨ÁË¡£·¢ ......

PythonÒì³£´¦ÀíÌåϵ¼ò½é

PythonÄÚ½¨Òì³£Ìåϵ½á¹¹
BaseException
+--¡¡SystemExit
+--¡¡KeyboardInterrupt
+--¡¡GeneratorExit
+--¡¡Exception
+--¡¡StopIteration
+--¡¡StandardError
|¡¡¡¡¡¡¡¡+--¡¡BufferError
|¡¡¡¡¡¡¡¡+--¡¡ArithmeticError
|¡¡¡¡¡¡¡¡|¡¡¡¡¡¡¡¡+--¡¡FloatingPointError
|¡¡¡¡¡¡¡¡|¡¡¡¡¡¡¡¡+--¡¡OverflowError
|¡¡¡¡ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ