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

Pyke ¼ò½é (3) £ºµ÷ÖÆ Python º¯Êý

¶Ô Python º¯ÊýµÄ"µ÷ÖÆ"£¬ÊÇÖ¸¶ÔÆä×ö³öºÏºõÐèÇóµÄÉèÖ᣾ßÌåµÄµ÷ÖÆ·½·¨£¬Êǽ«Æä²ÎÊýÉèΪ¹Ì¶¨Öµ£¨³£Êý£©¡£
É趨µ¥Ò»µÄ²ÎÊýÖµ
Ô­Ïȵĺ¯ÊýÊÇÕâÑùµÄ£º
>>> def foo(cooked, standard):
... print "foo called with cooked: %s, standard: %s" % \
... (cooked, standard) 
µ÷ÓÃËü£º
>>> foo('a', 'b')
foo called with cooked: a, standard: b 
²»¹ý£¬ÏëÒªµÄÊÇÈÃÕâ¸öº¯ÊýµÄµÚÒ»¸ö²ÎÊý£¬±ä³É"µ÷ÖƲÎÊý"£¬²¢ÇÒֻʣϵڶþ¸ö²ÎÊý¡£
ͨ¹ý Python ±ê×¼¿âÄ£¿éfunctoolsµÄÀàpartial£¬¿ÉÒÔ×öµ½¡£
>>> from functools import partial 
Óà partial µ÷ÖƵÚÒ»¸ö²ÎÊý£º
>>> cooked1 = partial(foo, 'cooked_value1') 
Ô­º¯Êý foo µÄµÚÒ»¸ö²ÎÊý£¬±»µ÷ÖƳÉΪº¯Êý cooked1£¬foo µÄµÚ¶þ¸ö²ÎÊý£¬³ÉÁË cooked1 µÄΨһ²ÎÊý¡£
>>> cooked1('value1')
foo called with cooked: cooked_value1, standard: value1
>>> cooked1('value2')
foo called with cooked: cooked_value1, standard: value2
 
¿ÉÒÔÓÃÆäËûÖµ£¬Éú³Éµ÷Öƺ¯Êý£º
>>> cooked2 = partial(foo, 'cooked_value2')
>>> cooked2('value1')
foo called with cooked: cooked_value2, standard: value1
>>> cooked2('value2')
foo called with cooked: cooked_value2, standard: value2
 
Ô­±¾Ò»¸öº¯Êý£¬ÏÖÔÚµ÷ÖƳÉÁËÁ½¸ö£¬Ê°빦±¶ºÇ¡£
>>> cooked1('value3')
foo called with cooked: cooked_value1, standard: value3
>>> cooked1('value4')
foo called with cooked: cooked_value1, standard: value4
>>> cooked2('value5')
foo called with cooked: cooked_value2, standard: value5
>>> cooked2('value6')
foo called with cooked: cooked_value2, standard: value6 
Èç·¨ÅÚÖÆ£¬¿ÉÓÉÔ­º¯ÊýÉú³ÉÈÎÒâ¶à¸öµ÷Öƺ¯Êý¡£
×ö³öº¯Êýµ÷ÓÃ˳Ðòͼ
ÓÃͬÑùµÄµ÷ÖƼ¼Êõ£¬¶Ôµ÷ÖƳöµÄº¯Êý£¬ÔٴνøÐе÷ÖÆ£¬¿ÉÒÔ²úÉúÏÂÒ»¼¶µ÷Öƺ¯Êý£¬......£¬ÓÉ´ËÖð²½Ðγɺ¯Êýµ÷ÓÃ˳Ðòͼ£º
>>> def bar(child_fun, a):
... print "bar called with:", a
... return child_fun(a) 
×¢Ò⣬º¯Êý bar µÄµÚÒ»²ÎÊýÊǸöÒýÓ㬼´º¯ÊýÃû¡£ÓÃÕâ¸ö°ì·¨£¬¿ÉÒÔµ÷ÖÆÈκβÎÊý£º
£¨ÆäÖÐµÄ float ºÍ min ÊÇ Python µÄÄÚ½¨º¯Êý£©
>>> bar_f


Ïà¹ØÎĵµ£º

beginning python summary chapter 6 ³éÏó

1¡¢Ê¹ÓÃdef¶¨Ò庯Êý
2¡¢º¯ÊýÎĵµ£ºÔÚº¯ÊýµÄ¿ªÍ·Ð´ÏÂ×Ö·û´®£¬Ëü¾Í»á×÷Ϊº¯ÊýµÄÒ»²¿·Ö½øÐд洢£¬³ÆΪ"Îĵµ×Ö·û´®"¡£
                    ÄÚ½¨µÄ½Ð×öhelpµÄº¯Êý·Ç³£ÓÐÓÃ,Èç¹ûÄãÔÚ½»»¥Ê½½âÊÍÆ÷ÖÐʹÓã¬Äã¿ÉÒԵõ ......

python ÕýÔò±í´ïʽºÍreÄ£¿é

ÕýÔò±í´ïʽÊÇËÑË÷¡¢Ìæ»»ºÍ½âÎö¸´ÔÓ×Ö·ûģʽµÄÒ»ÖÖÇ¿´ó¶ø±ê×¼µÄ·½·¨.
ÕýÔò±í´ïʽ£¨»ò RE£©ÊÇÒ»ÖÖСÐ͵ġ¢¸ß¶Èרҵ»¯µÄ±à³ÌÓïÑÔ£¬£¨ÔÚPythonÖУ©ËüÄÚǶÔÚPythonÖУ¬²¢Í¨¹ý re Ä£¿éʵÏÖ.×Ö·û´®Ò²Óкܶ෽·¨,¿ÉÒÔ½øÐÐËÑË÷ (index¡¢find ºÍ count)¡¢Ìæ»» (replace) ºÍ½â
Îö (split),µ«ËüÃǽöÏÞÓÚ´¦Àí×î¼òµ¥µÄÇé¿ö
re Ä£¿éʹ P ......

Python modules : os, subprocess and commands

1. What’s the difference between all of the os.popen() methods?
popen2 doesn't capture standard error, popen3 does capture standard
error and gives a unique file handle for it. Finally, popen4 captures
standard error but includes it in the same file object as standard
output.
os.popen()&n ......

Python Áбí

Python Áбí
listÊÇ´¦ÀíÒ»×éÓÐÐòÏîÄ¿µÄÊý¾Ý½á¹¹£¬¼´Äã¿ÉÒÔÔÚÒ»¸öÁбíÖд洢һ¸ö ÐòÁÐ µÄÏîÄ¿¡£¼ÙÏëÄãÓÐÒ»¸ö¹ºÎïÁÐ±í£¬ÉÏÃæ¼ÇÔØ×ÅÄãÒªÂòµÄ¶«Î÷£¬Äã¾ÍÈÝÒ×Àí½âÁбíÁË¡£Ö»²»¹ýÔÚÄãµÄ¹ºÎï±íÉÏ£¬¿ÉÄÜÿÑù¶«Î÷¶¼¶À×ÔÕ¼ÓÐÒ»ÐУ¬¶øÔÚPythonÖУ¬ÄãÔÚÿ¸öÏîÄ¿Ö®¼äÓöººÅ·Ö¸î¡£
ÁбíÖеÄÏîÄ¿Ó¦¸Ã°üÀ¨ÔÚ·½À¨ºÅÖУ¬ÕâÑùPython¾ÍÖªµÀÄãÊ ......

python ÅÀ³æ³ÌÐòÏê½â

1 #!/usr/bin/python ʹÓÃħ·¨×Ö·ûµ÷ÓÃpython
2
3 from sys import argv  µ¼ÈësysÊǵ¼Èëpython½âÊÍÆ÷ºÍËû»·¾³Ïà¹ØµÄ²ÎÊý
4 from os import makedirs,unlink,sep
osÖ÷ÒªÌṩ¶Ôϵͳ·¾¶£¬ÎļþÖØÃüÃûºÍɾ³ýÎļþËùÐèµÄº¯Êý
makedirsÊÇ´´½¨µÝ¹éÎļþ¼ÐµÄº¯Êý¡£±ÈÈç˵ÎÒÃÇÒª´´½¨Ò»¸öеÄĿ¼£¬/python/HTML/crawl,µ«ÊÇÄ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ