Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö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Ö®HTMLParser

"""A parser for HTML and XHTML."""
# This file is based on sgmllib.py, but the API is slightly different.
# XXX There should be a way to distinguish between PCDATA (parsed
# character data -- the normal case), RCDATA (replaceable character
# data -- only char and entity references and end tags a ......

pythonÎļþºÍ·¾¶²Ù×÷½éÉÜ

from http://blog.alexa-pro.cn/?p=189
1: os.listdir(path) //pathΪĿ¼
¹¦ÄÜÏ൱ÓÚÔÚpathĿ¼ÏÂÖ´ÐÐdirÃüÁ·µ»ØÎªlistÀàÐÍ
print os.listdir('..')
Êä³ö£º
[a,b,c,d]
2: os.path.walk(path,visit,arg)
path £ºÊǽ«Òª±éÀúµÄĿ¼
visit £ºÊÇÒ»¸öº¯ÊýÖ¸Õ룬º¯ÊýÔ²ÐÎΪ£º
callback(arg,dir,fileList)
ÆäÖÐargΪΠ......

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Ä£¿é

from link http://www.tt010.net/cms/show_article/1057.html ·¢±íÆÀÂÛ Post by : BossAdmin @[2009-12-12 17:11:20] views:115 adodb£ºÎÒÃÇÁìµ¼ÍÆ¼öµÄÊý¾Ý¿âÁ¬½Ó×é¼þ bsddb3£ºBerkeleyDBµÄÁ¬½Ó×é¼þ Cheetah-1.0£ºÎұȽÏϲ»¶Õâ¸ö°æ±¾µÄcheetah cherrypy£ºÒ»¸öWEB framework ctypes£ºÓÃÀ´µ÷Óö¯Ì¬Á´½Ó¿â DBUtils£ºÊý ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ