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

Python Ïß³Ìͬ²½

¶à¸öÖ´ÐÐÏ߳̾­³£Òª¹²ÏíÊý¾Ý£¬Èç¹û½ö½ö¶ÁÈ¡¹²ÏíÊý¾Ý»¹ºÃ£¬µ«ÊÇÈç¹û¶à¸öÏß³ÌÒªÐ޸Ĺ²ÏíÊý¾ÝµÄ»°¾Í¿ÉÄܳöÏÖÎÞ·¨Ô¤ÁϵĽá¹û¡£
    ¼ÙÈçÁ½¸öÏ̶߳ÔÏót1
ºÍt2
¶¼Òª¶ÔÊýÖµnum=0
½øÐÐÔö1ÔËË㣬ÄÇôt1
ºÍt2
¶¼¸÷¶Ônum
ÐÞ¸Ä10
´ÎµÄ»°£¬ÄÇônum
×îÖյĽá¹ûÓ¦¸ÃΪ20
¡£µ«ÊÇÈç¹ûµ±t1
È¡µÃnum
µÄֵʱ£¨¼ÙÈç´Ëʱnum
Ϊ0
£©£¬ÏµÍ³°Ñt1
µ÷¶ÈΪ“sleeping
”״̬£¬¶ø´Ëʱt2
ת»»Îª“running
”״̬£¬´Ëʱt2
»ñµÃµÄnum
µÄֵҲΪ0
£¬È»ºóËû°Ñnum+1
µÄÖµ1
¸³¸ønum
¡£ÏµÍ³ÓÖ°Ñt2
ת»¯Îª“sleeping
”״̬£¬t1
Ϊ“running
”״̬£¬ÓÉÓÚt1
ÒѾ­µÃµ½num
ֵΪ0
£¬ËùÒÔËûÒ²°Ñnum+1
µÄÖµ¸³¸øÁËnum
Ϊ1
¡£±¾À´ÊÇ2
´ÎÔö1
ÔËÐУ¬½á¹ûÈ´ÊÇnum
Ö»ÔöÁË1
´Î¡£ÀàËÆÕâÑùµÄÇé¿öÔÚ¶àÏß³ÌͬʱִÐеÄʱºòÊÇÓпÉÄÜ·¢ÉúµÄ¡£ËùÒÔΪÁË·ÀÖ¹ÕâÀàÇé¿öµÄ³öÏÖ¾ÍҪʹÓÃÏß³Ìͬ²½»úÖÆ¡£
    ×î¼òµ¥µÄͬ²½»úÖƾÍÊÇ“Ëø”
    Ëø¶ÔÏóÓÃthreading.RLock
Àà´´½¨
    mylock = threading.RLock()
    ÈçºÎʹÓÃËøÀ´Í¬²½Ïß³ÌÄØ£¿Ï߳̿ÉÒÔʹÓÃËøµÄacquire()
£¨»ñµÃ£©·½·¨£¬ÕâÑùËø¾Í½øÈë“locked
”״̬¡£Ã¿´ÎÖ»ÓÐÒ»¸öÏ߳̿ÉÒÔ»ñµÃËø¡£Èç¹ûµ±ÁíÒ»¸öÏß³ÌÊÔͼ»ñµÃÕâ¸öËøµÄʱºò£¬¾Í»á±»ÏµÍ³±äΪ“blocked
”״̬£¬Ö±µ½ÄǸöÓµÓÐËøµÄÏ̵߳÷ÓÃËøµÄrelease()
£¨ÊÍ·Å£©·½·¨£¬ÕâÑùËø¾Í»á½øÈë“unlocked
”״̬¡£“blocked
”״̬µÄÏ߳̾ͻáÊÕµ½Ò»¸ö֪ͨ£¬²¢ÓÐȨÀû»ñµÃËø¡£Èç¹û¶à¸öÏ̴߳¦ÓÚ“blocked
”״̬£¬ËùÓÐÏ̶߳¼»áÏȽâ³ý“blocked
”״̬£¬È»ºóϵͳѡÔñÒ»¸öÏß³ÌÀ´»ñµÃËø£¬ÆäËûµÄÏ̼߳ÌÐø³ÁĬ£¨“blocked
”£©¡£
import threading
mylock = threading.RLock()
class mythread(threading.Thread)
    ...
    def run(self ...):
        ...     #´Ë´¦ ²»¿ÉÒÔ
·ÅÖÃÐ޸Ĺ²ÏíÊý¾ÝµÄ´úÂë
        mylock.acquire()
        ...     #´Ë´¦ ¿ÉÒÔ
·ÅÖÃÐ޸Ĺ²ÏíÊý¾ÝµÄ´úÂë
        mylock.release()
   


Ïà¹ØÎĵµ£º

PythonÕýÔò±í´ïʽµÄ³£ÓÃÆ¥ÅäÓ÷¨


ÏÂÃæÁгöPythonÕýÔò±í´ïʽµÄ¼¸ÖÖÆ¥ÅäÓ÷¨£º
1.²âÊÔÕýÔò±í´ïʽÊÇ·ñÆ¥Åä×Ö·û´®µÄÈ«²¿»ò²¿·Ö
regex=ur"" #ÕýÔò±í´ïʽ
if re.search(regex, subject):
    do_something()
else:
    do_anotherthing()
2.²âÊÔÕýÔò±í´ïʽÊÇ·ñÆ¥ÅäÕû¸ö×Ö·û´®
regex=ur"\Z" #ÕýÔò±í´ïʽĩβÒÔ\ ......

python Eric µÄʹÓÃ

        ×î½üʹÓÃpython¹ý³ÌÖУ¬python½çÃæµÄ±à³Ì¹¤¾ßGTK-Python£¬µ«ÊǽçÃæµÄÃÀ¹ÛÐÔ²»ÈçQt-CreatorÖеÄQt-Designer£¬ÎÞ·¨ÊµÏÖÉè¼ÆÊÇÊÓͼ»æÖÆ£¬ÓеãÈÃÈËʧÍû¡£
        ÍøÉÏ·¢ÏÖÓÐÈ˽éÉÜpython Eric IDE,±È½ÏºÃÆ棬°²×°ÉÏ¿´¿´°É£º
  &nb ......

pythonÖÐdatetimeµÄ±È½Ï·½·¨Ê¹ÓÃ


pythonÖеÄdatetime moduleÊÇרÃÅ´¦Àíʱ¼äÏà¹ØÄÚÈݵÄÄ£¿é,¹¦ÄܺÜÇ¿´ó,µ«ÊÇ·´¶øÏԵñȽϸ´ÔÓ¡£
һϴúÂëÊÇÓÃÀ´Çó´ÓmysqlÖÐÈ¡µ½µÄtimestampºÍµ±Ç°Ê±¼ä±È½Ï£¬Çóʱ¼ä²îµÄ·½·¨
import datetime
lasttime=a.get_last_timestamp(sid=40)[-1]["last_time"] #È¡µ½timestamp
delta = datetime.datetime.now()-lasttime   # ......

ÔÚWindowsÏÂʹÓÃPython±à³Ì

Ò»¡¢Ê¹ÓÃPythonÐèÒªÖªµÀµÄ
ÔÚ Windows ÉÏ£¬°²×° Python ÓÐÁ½ÖÖÑ¡Ôñ¡£
1¡¢ActiveState ÖÆ×÷µÄ ActivePython ÊÇרÃÅÕë¶Ô Windows µÄ Python Ì×¼þ£¬Ëü°üº¬ÁËÒ»¸öÍêÕûµÄ Python ·¢²¼¡¢Ò»¸öÊÊÓÃÓÚPython ±à³ÌµÄ IDE ÒÔ¼°Ò»Ð© PythonµÄ Windows À©Õ¹£¬ÌṩÁËÈ«²¿µÄ·ÃÎÊ Windows APIs µÄ·þÎñ£¬ÒÔ¼° Windows×¢²á±íµÄ×¢²áÐÅÏ¢¡£ËäÈ ......

python ÈçºÎ·µ»Ø¶à¸öÖµ

ÈçºÎдһ¸ö·µ»Ø¶à¸öÖµµÄº¯Êý
º¯ÊýµÄreturn Óï¾äÖ»ÄÜ·µ»ØÒ»¸öÖµ£¬¿ÉÒÔÊÇÈκÎÀàÐÍ¡£
Òò´Ë£¬ÎÒÃÇ¿ÉÒÔ“·µ»ØÒ»¸ö tupleÀàÐÍ£¬À´¼ä½Ó´ïµ½·µ»Ø¶à¸öÖµ
”¡£
Àý:   x ³ýÒÔ y µÄÓàÊýÓëÉ̵ĺ¯Êý
def    F1 ( x, y ):
         a = x % y
  ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ