»°ËµPython£¨Î壩¿ªÊ¼Æð·É°É
С°×¶ÔÉϽڿÎÀïµÄ“СÂéȸ”ÐËȤ°»È»£¬ÕûÌì¾ÍÔÚËÞÉáµ·¹Ä¡£Õâ²»£¬¼¸ÌìÏÂÀ´ËûÒѾ¹¥ÏÂÊ®¼¸¸öÍøÕ¾ÁË¡£
С²Ëȴϲ»¶Ò»¸öÈË×øÔÚµçÄÔÅԱߣ¬Öå×Åüͷ£¬ÐÀÉÍ×ÅÕâÒ»ÐÐÐÐ×Ô¼º¿´²»¶®µÄ´úÂë¡£“ÕâЩ×Ö·ûºÃ¹ÖÒìѽ£¡”С²ËÍá×ÅÍ·£¬“ËüΪɶ½ÐÕýÔò±í´ïʽÄØ£¿”
°Ù¶Èһϣ¬ÖÕÓÚÖªµÀ¡£Ð¡²ËÔÚ½ñÌìÉÏ¿ÎÇ°ËƺõÁìÎòµ½ÁËÕýÔò±í´ïʽµÄÕæÚУ¬ÐÄÖÐÇÔϲ£º“½ñÌìÎÒÒªºÃºÃÏÔ°Úһϣ¬¿´Ë»¹ËµÎҲˡ£”
ûÏëµ½£¬½ñÌì´óÅ£ÀÏʦȴ¶ÔÕýÔò±í´ïʽֻ×ÖδÌá¡£
“Ê×ÏÈ£¬ÎÒÃÇÓ¦¸ÃÖªµÀ×Ô¼ºÏëҪʲô£¡”´óÅ£ÀÏʦÏòͬѧÃǽ²µÀ£¬·Â·ðÊÇÔÚÉÏÕÜѧ¿Î£¬“ÎÒÃǵÄÅÀ³æCrawlerÏëÒªµÃµ½Ê²Ã´ÄØ£¿”
CrawlerÖ»ÓÐÒ»¸öÄ¿µÄ£¬ÄǾÍÊÇ»ñÈ¡Ö¸¶¨ÍøÒ³µÄÄÚÈÝ£¬ÌáÈ¡ÀïÃæµÄÁ´½Ó¡£Èç´Ëµ¥Ò»µÄÄ¿µÄÈçºÎʵÏÖÄØ£¿
ÏÖÔÚÎÒÃÇ¿ÉÒÔ²ÂÏëÒ»ÏÂCrawlerµÄ¹¹³É£º
1¡¢Crawler±ØÐëÓÐÒ»¸öÀàÊÇÓÃÀ´ÅÀÐеģ¬ÃûΪCrawl¡£Ê×ÏÈ£¬Ëü½ÓÊÕControl´«µÝµÄÁ½¸ö¶ÓÁУºÒ»¸öÊÇÌṩµØÖ·µÄ£¬Ò»¸öÊÇÓÃÀ´´¢´æCrawlÅÀÐеõ½µÄÐÅÏ¢¡£
2¡¢CrawlerÊÇ»ùÓÚ¶àÏ̵߳ģ¬¸ÃÀà½ÐWorker¡£CrawlÀàÔÚÅÀÐÐʱʹÓÃWorkerʵÏÖ¶àÏ̡߳£WorkerÀà»áÌṩһ¸öÏ̳߳أ¬Ê¹ÅÀÐÐÓÐÐò¡¢Îȶ¨ºÍ¿ìËÙ¡£
3¡¢Crawler±ØÐëÓÐÒ»¸öÀàÀ´¼Ç¼ÍøÒ³µÄÏà¹ØÐÅÏ¢£¬°üÀ¨Á´½Ó¹Øϵ¡¢×¥È¡Ê±¼ä¡¢ÓÅÏȼ¶µÈ£¬ËüÊÇÒ»¸öÊý¾Ý½á¹¹£¬ÊµÏÖËü²¢²»ÄÑ¡£
Ïȱ𼱣¬ÔÚ±àдSparrowµÄCrawler֮ǰ£¬ÓбØÒªÑо¿Ò»ÏÂËüÊÇÈçºÎ±»µ÷Óõġ£
CrawlerÓÐÒ»¸ö¿ØÖÆÆ÷½ÐControl£¬Ëü½«Ò»ÏµÁÐÍøַдµ½Ò»¸ö¶ÓÁÐÀ¹©CrawlerÅÀÐС£Control³õʼ»¯Ò»¸öCrawler£¬¶ÓÁÐÒÔ²ÎÊýµÄÐÎʽ´«µÝ¸øCrawler£¬Crawler¿ªÊ¼¹¤×÷ºó£¬Á¢¼´´Ó¸Ã¶ÓÁÐÀï¶ÁÈëÒ»¸öÍøÖ·£¬½øÐÐһϵÁвÙ×÷ºó·µ»Ø¸ÃÍøÒ³µÄÄÚÈݺÍÍøÒ³ÄÚµÄËùÓÐÁ´½Ó£¬²¢½«ËüÃǷŵ½ÁíÒ»¸ö¶ÓÁÐÀï¡£ÕâÁ½¸ö¶ÓÁж¼ÊÇÓÉControlÌṩµÄ£¬CrawlerÖ»¸ºÔðץȡÍøÒ³ºÍ·ÖÎöÁ´½Ó¡£
ÕâÑù£¬ÎÒÃǾÍÇå³þÁË£ºÈç¹û½«Crawler±È×÷ÊֵĻ°£¬Control¾ÍÊÇ´óÄÔ¡£ControlÓÖÊÇÔõÑùʵÏÖÄØ£¿
ControlÌṩ¸øCrawlerÁ½¸ö¶ÓÁУ¬²¢Æô¶¯Crawler¡£³õʼ»¯CrawlerµÄÓï¾äΪ
crawler=Crawler(request_queue,result_queue)
“Ϊʲô²»ÈÃCrawler×Ô¼ºÑ»·Ö´ÐÐÄØ£¿”С°×ÎʵÀ¡£
ÔÒòÓжþ£º
1¡¢ÎÒÃÇÐèÒª¶ÔÅÀÐкóµÃµ½µÄ½á¹û½øÐд¦Àí£¬Ö»ÄÜÈÃCrawlerÅÀÐÐÎÒÃÇÏëÒªµÄÍøÒ³£¬¶ø²»ÊÇÈÃÅÀ³æÂþÎÞÄ¿µÄµÄÂҹ䡣
2¡¢ÈÃCrawler×Ô¼ºÑ»·ÈÝÒ×Ôì³ÉËÀÑ»·£¬µ¼ÖÂÒç³öÉõÖÁ±ÀÀ£¡£
“ControlºÃ¼òµ
Ïà¹ØÎĵµ£º
1£¬±àдServer.py
import socket
s=socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
s.bind(('localhost',8081))
while True:
data,addr=s.recvfrom(1024)
print 'receive:',data,'from',addr
2£¬±àдClient.py
import socket
s=socket.socket(socket.AF_INET,socket.SOC ......
¶ÓÁУº
Óë¶ÑÕ»ÀàËÆ£¬Í¨¹ýpythonµÄÁбíÀàÐÍÀ´ÊµÏÖ£¬²Î¿¼ help(list)
shoplist=['apple','mango','carrot','banana']
print 'I have',len(shoplist),'items to purchase'
print 'these items are:'
for item in shoplist:
print item,
shoplist.append('rice')
print 'my shopping list is now', shoplist
shoplist. ......
С°×ÊǸö΢ÈíÃÔ£¬ËûµÄżÏñÊDZȶû´óÊ壬ÔÒòµ±È»ÊǵØÇòÈ˶¼ÖªµÀÀ²¡£´ó¶þµÄʱºò£¬ËûµÄ“ê¡Ñ§¼Æ»®”ÔøÒ»¶ÈµÃ³Ñ£¬ÔÒòÊÇËû¹Ò¿ÆÌ«¶à¡£µ±È»£¬´óÈýÐÂѧÆÚ¿ªÊ¼µÄʱºò£¬Ãæ¶Ô¹«ÖÚÖÊÒÉ£¬Ð¡°×Õ¾ÔÚÒÎ×ÓÉÏ£¬Ïñ¼«ÁË¡¶´óÄÚÃÜ̽ÁãÁã·¢¡·ÀïµÄÎ÷ÃÅ´µÑ©£º“ÊÀ½çÊ׸»±È²»Ò»¶¨Óжà³öÉ«£¬ÕâÖ»²»¹ýÊÇÄãÃÇÕâЩÐǶ·ÊÐÃñÒ»ÏáÇéÔ¸µÄÏë·¨° ......
list.append(item)
list.extend(sequence)
http://docs.python.org/tutorial/datastructures.html
http://docs.python.org/library/functions.html Õ⼸Ìì¿´Ò»ÏÂ
python howto
¶÷¡£python documentation ȷʵºÜºÃºÜÇ¿´ó°¡£¡
list.append(x)Add an item to the end of the list; equivalent to a[len(a):]&n ......
[Ô´´]Python(pysvn)ÌáÈ¡svn°æ±¾¼ä¸Ä¶¯ÎļþÁбí
by AKara 2010.04.29 @ http://blog.csdn.net/akara @ akaras@163.com
---------------------------------------------------------------------
Ï£ÍûʵÏÖÒ»¸öÌáÈ¡Á½¸ösvn revision¼äÓб䶯(Ôö/ɾ/¸Ä)µÄÎļþµÄÁбí
µÄÃüÁîÐй¤¾ß£»¿ÉÒÔ°ïÎÒÃÇÏîÄ¿×öһЩÁ÷ ......