RubyºÍPythonµÄÓï·¨±È½Ï
RubyºÍPythonµÄÓï·¨±È½Ï
ÆäʵRubyºÍPython·Ç³£½Ó½ü£¬±È´ó¶àÊý±ðµÄÓïÑÔÒª½Ó½üµÄ¶à£¬ËùÒÔϲ»¶ÓÃɶ¾ÍÓÃɶ£¨´óʵ»°£¬ËäȻҲÊÇ·Ï»°£©¡£Óï·¨ÉϵIJî±ðËäÈ»ÓÐÄÇôһµã£¬´ó²¿·ÖÊÇsyntax sugar£¬ÎÒ¶·µ¨ÉÔ΢Áм¸¸ö£¨pythonÎÒÒ²ÍüµÃ²î²»¶àÁË£¬²»¶ÔµÄ´ó¼Ò¾¡¹ÜÀ´±Þʬ°É£©£¬µ«ÊÇÖ÷Òª²îÒ컹ÊÇÉè¼Æ˼ÏëÉϵģºÁé»îvsÃ÷È·. ÎÒ²»ÈÏΪÁ½ÕßÔÚÉú²úÁ¦ÉÏ»áÓÐʲô²î±ð£¬Èç¹ûÄãÊìϤµÄ»°¡£*×¢Ò⣬½öÏÞÓïÑÔ±¾ÉíµÄ±È½Ï¡£
±¾ÎÄÍƼö£ºRubyÈëÃŽ̳ÌÓë¼¼ÇÉ´óÈ«
RubyºÍPythonµÄ±È½ÏÁбí
1. rubyµÄcase¿ÉÒÔÆ¥ÅäºÜ¶à¶«Î÷£º·¶Î§/Êý×飬¶ÔÏó£¬ÕýÔò±í´ï£¬pythonûÓÐcase/switch¶øʹÓÃif/else±È½ÏËÀ°åµã
2. pythonµÄËõ½øºÜƯÁÁ£¬ËäÈ»ÓÐʱ»áÔì³ÉЩÐíÂé·³¡£rubyµÄendÂùÄÑ¿´µÄ£¬ËùÒÔ´ó¼Ò¶¼±»±Æµ±one liner£¨ÍæЦ£©
3. ¸Ð¾õÉÏruby±Èpython¸üOO,µ±È»ÕâÒ²¿ÉÄÜÊÇÒòΪpython²»ÌᳫÓÃÄÇЩ¸Ä±ä¶ÔÏóÄÚ²¿¹¹ÔìµÄ‘¼¿Á©’Ôì³ÉµÄ´í¾õ
4. pythonÓÐlist comprehension, rubyûÓÐ:(
5. pythonÓÐÕæÕýµÄkeyword argument, rubyÓÃhashÄ£Ä⣬µ±È»Êµ¼ÊÓÃÆðÀ´Ã»Ê²Ã´²î±ð
6. pythonµÄselfºÜÌÖÑᣬrubyûÓÐÄÇÖÖ·±ËöµÄ¶«Î÷
7. reflection£¬rubyÄÚÖÃÁ˺ܶ෽·¨£¬±ÈÈçobject.methods£¬¶øpython°ÑÕâЩÐÅÏ¢´æÔÚÌØÊâµÄ×ÖµäÀï¡£²î²»¶à
8. rubyµÄblock¹¦ÄܺÜÇ¿£¬pythonµÄlambdaÖ»ÄÜ·µ»Øµ¥Ò»Öµ
9. rubyµÄopen classÒѾÉùÃ÷Ô¶²¥£¬¿ÉÒÔÍæ³ö2.days.agoÕâÑùµÄ»¨Ñù£¬pythonºÃÏñû·¨Ö±½ÓÐÞ¸ÄÄÚÖÃÀàÒ²·´¶ÔÕâô×ö¡£
10. pythonÐèÒªÓÃ@classmethodÐÞÊÎÉùÃ÷Àà·½·¨£¬rubyÊÇÄÚ½¨
11. rubyÓе¥×Ó·½·¨£¬Ò²¾Í¶Ô¶ÔÏ󵥶À¶¨ÖÆ£¬python²»ÖªµÀÓÐûÓÐÀàËƸÅÄî
12. rubyÓÐmethod_missing»úÖÆ£¬python¿ÉÒÔʹÓÃ__getattr__½Ø»ñ䶨Òå·½·¨(from qiezi)
13. rubyʹÓõ¥¼Ì³Ð+mixin£¬pythonʹÓöàÖؼ̳У¬²»¹ýpythonÒ²ÓÐmixin
14. rubyÓÐattr_*ϵÁÐÓï·¨helper£¬Ê¡È´×Ô¼ºÐ´Ò»¶Ñsetter/getter, pythonµÄproperty·½·¨»¹ÊǵÃ×Ô¼ºÐ´setter/getter
15. rubyºÍpython¶¼Ê¹ÓÃduck typing£¬²»¹ýpythonÒ²ÓÐÒ»Ì×ÏÔʽµÄinterface»úÖÆ(´Ózope3²¢ÈëÄÚºËÁËô£¿)
16. rubyµÄº¯Êýµ÷ÓÃÀ¨ºÅÊÇ¿ÉÊ¡µÄ£¬ÉÔ΢ÉÙÇü¸Ï¼üÅÌ¡£pythonĬÈÏûÀ¨ºÅÒ²²»´ø²ÎÊýµÄ»°·µ»Øº¯Êý±¾ÉíµÄÒ»¸öÒýÓá£
17. ÎÒ²»Çå³þpythonµÄmeta programmingÄܵ½Ê²Ã´³Ì¶È£¬Ö»ºÃµÈ´óÅ£À´ËµËµÁË¡£Ö»ÊǾõµÃpythoner²»³£ÓÃÄǸö£¬Ò²Ðí¾õµÃ»á°Ñ³ÌÐòÂß¼¸ãµÃ»Þɬ²»Ã÷¡£
18. ruby´Óperl¼Ì³ÐÁËÒ»²¿·ÖÄÑ¿´µÄ¶«Î÷£¬±ÈÈçºÜ¶àÔ¤¶¨ÒåµÄ$x³£Á¿
19. rubyÄÚ½¨ÕýÔò±í´ï£¬·½±ãÒ»µã
Ïà¹ØÎĵµ£º
¹ýÁ¿µÄ²ÎÊý
ÔÚÔËÐÐʱ֪µÀÒ»¸öº¯ÊýÓÐʲô²ÎÊý£¬Í¨³£ÊDz»¿ÉÄܵġ£ÁíÒ»¸öÇé¿öÊÇÒ»¸öº¯ÊýÄܲÙ×÷ºÜ¶à¶ÔÏ󡣸üÓÐÉõÕߣ¬µ÷ÓÃ×ÔÉíµÄº¯Êý±ä³ÉÒ»ÖÖapiÌṩ¸ø¿ÉÓõÄÓ¦Óá£
¶ÔÓÚÕâЩÇé¿ö£¬pythonÌṩÁËÁ½ÖÖÌرðµÄ·½·¨À´¶¨Ò庯ÊýµÄ²ÎÊý£¬ÔÊÐíº¯Êý½ÓÊܹýÁ¿µÄ²ÎÊý£¬²»ÓÃÏÔʽÉùÃ÷²ÎÊý¡£ÕâЩ“¶îÍ┵IJÎÊýÏÂÒ»²½ÔÙ½âÊÍ¡£
×¢Òâa ......
python µÄÄÚǶtimeÄ£°å·Ò뼰˵Ã÷
Ò»¡¢¼ò½é
timeÄ£¿éÌṩ¸÷ÖÖ²Ù×÷ʱ¼äµÄº¯Êý
˵Ã÷£ºÒ»°ãÓÐÁ½ÖÖ±íʾʱ¼äµÄ·½Ê½:
µÚÒ»ÖÖÊÇʱ¼ä´ÁµÄ·½Ê½(Ïà¶ÔÓÚ1970.1.1 00:00:00ÒÔÃë¼ÆËãµÄÆ«ÒÆÁ¿),ʱ¼ä´ÁÊÇΩһµÄ
µÚ¶þÖÖÒÔÊý× ......
def getText(self,nodelist):
rc=""
for node in nodelist:
if node.nodeType == node.TEXT_NODE or node.nodeType == node.CDATA_SECTION_NODE:
rc = rc + node.data
return rc
def parseXML(self,requesturl,xml):
dom = minidom.parse(requesturl)
for node in dom.getElementsByTagName('ca ......
urllibÄ£¿éÌṩµÄÉϲã½Ó¿Ú£¬Ê¹ÎÒÃÇ¿ÉÒÔÏñ¶ÁÈ¡±¾µØÎļþÒ»Ñù¶ÁÈ¡wwwºÍftpÉϵÄÊý¾Ý¡£Ã¿µ±Ê¹ÓÃÕâ¸öÄ£¿éµÄʱºò£¬ÀÏÊÇ»áÏëÆð¹«Ë¾²úÆ·µÄ¿Í»§¶Ë£¬Í¬ÊÂÓÃC++ÏÂÔØWebÉϵÄͼƬ£¬ÄÇÖÖ“Í´¿à”µÄ±íÇé¡£ÎÒÒÔÇ°·Òë¹ýlibcurl½Ì³Ì£¬ÕâÊÇÔÚC/C++»·¾³Ï±ȽϷ½±ãʵÓõÄÍøÂç²Ù×÷¿â£¬Ïà±ÈÆðlibcurl£¬PythonµÄurl ......