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

PythonÏ̱߳à³Ì£¨Èý£©Í¬²½¶ÓÁÐ

ÎÒÃǾ­³£»á²ÉÓÃÉú²úÕß/Ïû·ÑÕß¹ØÏµµÄÁ½¸öÏß³ÌÀ´´¦ÀíÒ»¸ö¹²Ïí»º³åÇøµÄÊý¾Ý¡£ÀýÈçÒ»¸öÉú²úÕßÏ߳̽ÓÊÜÓû§Êý¾Ý·ÅÈëÒ»¸ö¹²Ïí»º³åÇøÀµÈ´ýÒ»¸öÏû·ÑÕßÏ̶߳ÔÊý¾ÝÈ¡³ö´¦Àí¡£µ«ÊÇÈç¹û»º³åÇøµÄ̫С¶øÉú²úÕߺÍÏû·ÑÕßÁ½¸öÒì²½Ï̵߳ÄËٶȲ»Í¬Ê±£¬ÈÝÒ׳öÏÖÒ»¸öÏ̵߳ȴýÁíÒ»¸öÇé¿ö¡£ÎªÁ˾¡¿ÉÄܵÄËõ¶Ì¹²Ïí×ÊÔ´²¢ÒÔÏàͬËٶȹ¤×÷µÄ¸÷Ï̵߳ĵȴýʱ¼ä£¬ÎÒÃÇ¿ÉÒÔʹÓÃÒ»¸ö“¶ÓÁДÀ´Ìṩ¶îÍâµÄ»º³åÇø¡£
´´½¨Ò»¸ö“¶ÓÁД¶ÔÏó
import Queue
myqueue = Queue.Queue(maxsize = 10)
Queue.QueueÀ༴ÊÇÒ»¸ö¶ÓÁеÄͬ²½ÊµÏÖ¡£¶ÓÁг¤¶È¿ÉΪÎÞÏÞ»òÕßÓÐÏÞ¡£¿Éͨ¹ýQueueµÄ¹¹Ô캯ÊýµÄ¿ÉÑ¡²ÎÊýmaxsizeÀ´É趨¶ÓÁг¤¶È¡£Èç¹ûmaxsizeСÓÚ1¾Í±íʾ¶ÓÁ㤶ÈÎÞÏÞ¡£
½«Ò»¸öÖµ·ÅÈë¶ÓÁÐÖÐ
myqueue.put(10)
µ÷ÓöÓÁжÔÏóµÄput()·½·¨ÔÚ¶Óβ²åÈëÒ»¸öÏîÄ¿¡£put()ÓÐÁ½¸ö²ÎÊý£¬µÚÒ»¸öitemΪ±ØÐèµÄ£¬Îª²åÈëÏîÄ¿µÄÖµ£»µÚ¶þ¸öblockΪ¿ÉÑ¡²ÎÊý£¬Ä¬ÈÏΪ1¡£Èç¹û¶ÓÁе±Ç°Îª¿ÕÇÒblockΪ1£¬put()·½·¨¾Íʹµ÷ÓÃÏß³ÌÔÝÍ£,Ö±µ½¿Õ³öÒ»¸öÊý¾Ýµ¥Ôª¡£Èç¹ûblockΪ0£¬put·½·¨½«Òý·¢FullÒì³£¡£
½«Ò»¸öÖµ´Ó¶ÓÁÐÖÐÈ¡³ö
myqueue.get()
µ÷ÓöÓÁжÔÏóµÄget()·½·¨´Ó¶Óͷɾ³ý²¢·µ»ØÒ»¸öÏîÄ¿¡£¿ÉÑ¡²ÎÊýΪblock£¬Ä¬ÈÏΪ1¡£Èç¹û¶ÓÁÐΪ¿ÕÇÒblockΪ1£¬get()¾Íʹµ÷ÓÃÏß³ÌÔÝÍ££¬Ö±ÖÁÓÐÏîÄ¿¿ÉÓá£Èç¹ûblockΪ0£¬¶ÓÁн«Òý·¢EmptyÒì³£¡£
ÎÒÃÇÓÃÒ»¸öÀý×ÓÀ´Õ¹Ê¾ÈçºÎʹÓÃQueue
# queue_example.py
from Queue import Queue
import threading
import random
import time
# Producer thread
class Producer(threading.Thread):
def __init__(self, threadname, queue):
threading.Thread.__init__(self, name = threadname)
self.sharedata = queue
def run(self):
for i in range(20):
print self.getName(),'adding',i,'to queue'
self.sharedata.put(i)
time.sleep(random.randrange(10)/10.0)
print self.getName(),'Finished'
# Consumer thread
class Consumer(threading.Thread):
def __init__(self, threadname, queue):
threading.Thread.__init__(self, name = threadname)
self.sharedata = queue
def run(self):
for i in range(20):
print self.getName(),'got a value:',self.sharedata.get()
time.sleep(random.randrange(10)/10.0)
print self.getName(),'Finished'
# Main thread
def main():
queue = Queue()
producer = Producer('Producer', queue)
consumer =


Ïà¹ØÎĵµ£º

pythonʱ¼äתΪʱ¼ä´Á

ÕÒÁ˰ëÌìûÕÒ×Å£¬ÖÕÓÚÔÚÓ¢ÎÄÕ¾µãÉÏÕÒµ½£¬»¹ÓиÐлȺÀïµÄʯͷºÍÇòÃÔ
>>> s = datetime.datetime(2009,1,1)
>>> time.mktime(s.timetuple())
1230739200.0
±ðÍ⸶һ¸öpython¶Ôʱ¼äµÄһЩº¯Êý£¬ºÜºÃÓõÄ
ÎÒÃÇÏȵ¼Èë±ØÐëÓõ½µÄÒ»¸ömodule
>>> import time
ÉèÖÃÒ»¸öʱ¼äµÄ¸ñʽ£¬ÏÂÃæ»áÓõ½
& ......

Python´úÂë¼ÓÃÜ Ô´Âë±£»¤ pycÎļþ'×Ö½ÚÂë'

from   http://blog.alexa-pro.cn/?p=349
ÄÚÈݸÅÒª:Python´úÂë¼ÓÃÜ,Ô´Âë±£»¤,´úÂë±£»¤,pycÎļþ
------------------------------------------------
¹ØÓÚpython´úÂë±£»¤ÔÚÍøÉϺÃÏñһֱûÓкܺõĽéÉÜ,¿ÉÄܺÍPYTHONµÄÉè¼Æ³õÖÔ"¿ªÔ´"ÓйØ,µ«Ô½À´Ô½¶àµÄÐÖµÜдµÄ¼ÓÈëPYTHONÕóÓª,¿ª·¢¹¤¾ßÓÃ;¸÷Òì,ÔÚÉÌÒµÓ¦ÓÃÖдúÂë± ......

python hidden features

from http://stackoverflow.com/questions/101268/hidden-features-of-python
http://www.okpython.com/bbs/thread-3434-1-1.html
http://www.okpython.com/bbs/thread-3436-1-2.html
http://www.okpython.com/bbs/thread-3437-1-2.html
http://www.okpython.com/bbs/thread-3438-1-1.html
http://www.okpython.com/bb ......

¶ÔPython½ø³Ì½øÐÐÈ«½âÎö

ÏÂÃæ¶ÔPython½ø³Ì½øÐÐÉîÈë¶ø×ÐϸµÄѧϰ£¬Ê×ÏÈÏÈÈôó¼ÒÁ˽âÏÂʲôÊÇPython½ø³Ì£¬ÒÔ¼°ÔÚ¶ÔPython½ø³Ì½øÐд¦ÀíʱעÒâµÄÏà¹ØÎÊÌ⣬½ÓÏÂÀ´£¬¾ÍÓÉÎÒ¸ø´ó¼Ò½øÐнéÉÜѧϰ£¬½ö¹©´ó¼Òѧϰ¡£
²»¹ý£¬ËäÈ»½ø³Ì¿ÉÔÚµ¥¶ÀµÄÄÚ´æ¿Õ¼äÖÐÖ´ÐУ¬µ«³ý·ÇÕâЩPython½ø³ÌÔÚµ¥¶ÀµÄ´¦ÀíÆ÷ÉÏÖ´ÐУ¬·ñÔò£¬Êµ¼Ê²¢²»ÊǓͬʱ”ÔËÐеġ£ÊÇÓɲÙ×÷ ......

Pythonѧϰ֮OS¿â

OS¿âÌṩÁËʹÓø÷ÖÖ²Ù×÷ϵͳ¹¦ÄܵĽӿڡ£
os.name ·µ»Øµ±Ç°²Ù×÷ϵͳÃû£¬¶¨ÒåÁË'posix'£¬'nt'£¬'mac'£¬'os2'£¬'ce'£¬'java'£¨ÎÒʹÓÃwin7/python3.1,Êä³öµÄÊÇnt¡£posix²»ÖªµÀÊÇʲôϵͳ£¬macÓ¦¸ÃÊÇApple»ú°É£¬os2Ò²²»ÖªµÀÊÇʲô¶«¶«£¬ceÓ¦¸ÃÊÇwinCE°É£¬ÕâÑùµÄ»°£¬pythonÓ¦¸ÃÖ§³ÖÏòCEÒÆÖ²°¡£¬Å¼×Ô¼ºÊÔ¹ý£¬Ã»±àÒë³É¹¦£¬java¹À¼ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ