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
Ïà¹ØÎĵµ£º
ÔÎĵØÖ· http://www.javaeye.com/wiki/Python/1371-python-graphics-library-pil-python-image-library-introduction
¹ØÓÚPIL¿âµÄһЩ¸ÅÄî
pilÄÜ´¦ÀíµÄͼƬ
ÀàÐÍ
pil¿ÉÒÔ´¦Àí¹âդͼƬ(ÏñËØÊý¾Ý×é³ÉµÄµÄ¿é)¡£
ͨµÀ
Ò»¸öͼƬ¿ÉÒÔ°üº¬Ò»µ½¶à¸öÊý¾ÝͨµÀ£¬Èç¹ûÕâЩͨµÀ¾ßÓÐÏàͬµÄάÊýºÍÉî¶È£¬PilÔÊÐí½«ÕâЩͨµÀ½øÐеþ¼Ó ......
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 ×Öµä
×ÖµäÀàËÆÓÚÄãͨ¹ýÁªÏµÈËÃû×Ö²éÕÒµØÖ·ºÍÁªÏµÈËÏêϸÇé¿öµÄµØÖ·²¾£¬¼´£¬ÎÒÃǰѼü£¨Ãû×Ö£©ºÍÖµ£¨ÏêϸÇé¿ö£©ÁªÏµÔÚÒ»Æð¡£×¢Ò⣬¼ü±ØÐëÊÇΨһµÄ£¬¾ÍÏñÈç¹ûÓÐÁ½¸öÈËÇ¡ÇÉͬÃûµÄ»°£¬ÄãÎÞ·¨ÕÒµ½ÕýÈ·µÄÐÅÏ¢¡£
×¢Ò⣬ÄãÖ»ÄÜʹÓò»¿É±äµÄ¶ÔÏ󣨱ÈÈç×Ö·û´®£©À´×÷Ϊ×ÖµäµÄ¼ü£¬µ«ÊÇÄã¿ÉÒÔ²»¿É±ä»ò¿É±äµÄ¶ÔÏó×÷Ϊ×Öµäµ ......
×ֵ䣨Dictionary£©ÊÇÒ»ÖÖÓ³Éä½á¹¹µÄÊý¾ÝÀàÐÍ£¬ÓÉÎÞÐòµÄ“¼ü£Öµ¶Ô”×é³É¡£×ÖµäµÄ¼ü±ØÐëÊDz»¿É¸Ä±äµÄÀàÐÍ£¬È磺×Ö·û´®£¬Êý×Ö£¬tuple£»Öµ¿É
ÒÔΪÈκÎpythonÊý¾ÝÀàÐÍ¡£
1¡¢Ð½¨×Öµä
>>> dict1={}
#½¨Á¢Ò»¸ö¿Õ×Öµä
>>> type(dict1)
<ty ......
formatter Ä£¿é
formatter Ä£¿éÌṩÁËһЩ¿ÉÓÃÓÚ htmllib µÄ¸ñʽÀà( formatter classes ).
ÕâЩÀàÓÐÁ½ÖÖ, formatter ºÍ writer . formatter ½« HTML ½âÎöÆ÷µÄ±êÇ©ºÍÊý¾ÝÁ÷ת»»ÎªÊʺÏÊä³öÉ豸µÄʼþÁ÷( event stream ), ¶ø writer ½«Ê¼þÁ÷Êä³öµ½É豸ÉÏ.
´ó¶àÇé¿öÏÂ, Äã¿ÉÒÔʹÓà AbstractFormatter Àà½øÐиñʽ»¯. Ëü»á¸ù¾ ......