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

pythonÄ£¿éÖ®codecs

python¶Ô¶à¹úÓïÑԵĴ¦ÀíÊÇÖ§³ÖµÄºÜºÃµÄ£¬Ëü¿ÉÒÔ´¦ÀíÏÖÔÚÈÎÒâ±àÂëµÄ×Ö·û£¬ÕâÀïÉîÈëµÄÑо¿Ò»ÏÂpython¶Ô¶àÖÖ²»Í¬ÓïÑԵĴ¦Àí¡£
    ÓÐÒ»µãÐèÒªÇå³þµÄÊÇ£¬µ±pythonÒª×ö±àÂëת»»µÄʱºò£¬»á½èÖúÓÚÄÚ²¿µÄ±àÂ룬ת»»¹ý³ÌÊÇÕâÑùµÄ£º
        Ô­ÓбàÂë -> ÄÚ²¿±àÂë ->
Ä¿µÄ±àÂë
   
pythonµÄÄÚ²¿ÊÇʹÓÃunicodeÀ´´¦ÀíµÄ£¬µ«ÊÇunicodeµÄʹÓÃÐèÒª¿¼ÂǵÄÊÇËüµÄ±àÂë¸ñʽÓÐÁ½ÖÖ£¬Ò»ÊÇUCS-2£¬ËüÒ»¹²ÓÐ65536¸öÂë
룬ÁíÒ»ÖÖÊÇUCS-4£¬ËüÓÐ2147483648g¸öÂëλ¡£¶ÔÓÚÕâÁ½ÖÖ¸ñʽ£¬python¶¼ÊÇÖ§³ÖµÄ£¬Õâ¸öÊÇÔÚ±àÒëʱͨ¹ý--enable-
unicode=ucs2»ò--enable-unicode=ucs4À´Ö¸¶¨µÄ¡£ÄÇôÎÒÃÇ×Ô¼ºÄ¬ÈÏ°²×°µÄpythonÓеÄʲô±àÂëÔõôÀ´È·¶¨ÄØ£¿ÓÐÒ»¸ö
°ì·¨£¬¾ÍÊÇͨ¹ýsys.maxunicodeµÄÖµÀ´Åжϣº
import
 sys
print
 sys.maxunicode
    Èç¹ûÊä³öµÄֵΪ65535,ÄÇô¾ÍÊÇUCS-2,Èç¹ûÊä³öÊÇ1114111¾ÍÊÇUCS-4±àÂë¡£
ÎÒÃÇÒªÈÏʶµ½Ò»µã£ºµ±Ò»¸ö×Ö·û´®×ª»»ÎªÄÚ²¿±àÂëºó£¬Ëü¾Í²»ÊÇstrÀàÐÍÁË£¡ËüÊÇunicodeÀàÐÍ£º

=
 
"
·ç¾í²ÐÔÆ
"
print
 type(a)

=
 a.unicode(a, 
"
gb2312
"
)
print
 type(b)
Êä³ö£º
<type 'str'>
<type 'unicode'>
Õâ¸öʱºòb¿ÉÒÔ·½±ãµÄÈÎÒâת»»ÎªÆäËû±àÂ룬±ÈÈçת»»Îªutf-8:

=
 b.encode(
"
utf-8
"
)
print
 c
cÊä³öµÄ¶«Î÷¿´ÆðÀ´ÊÇÂÒÂ룬ÄǾͶÔÁË£¬ÒòΪÊÇutf-8µÄ×Ö·û´®¡£
   
ºÃÁË£¬¸Ã˵˵codecsÄ£¿éÁË£¬ËüºÍÎÒÉÏÃæ˵µÄ¸ÅÄîÊÇÃÜÇÐÏà¹ØµÄ¡£codecsרÃÅÓÃ×÷±àÂëת»»£¬µ±È»£¬Æäʵͨ¹ýËüµÄ½Ó¿ÚÊÇ¿ÉÒÔÀ©Õ¹µ½ÆäËû¹ØÓÚ´úÂë·½Ãæ
µÄת»»µÄ£¬Õâ¸ö¶«Î÷ÕâÀï²»Éæ¼°¡£
#
-*- encoding: gb2312 -*-
import
 codecs, sys
print
 
'
-
'
*
60
#
 ´´½¨gb2312±àÂëÆ÷
look  
=
 codecs.lookup(
"
gb2312
"
)
#
 ´´½¨utf-8±àÂëÆ÷
look2 
=
 codecs.lookup(
"
utf-8
"
)

=
 
"
ÎÒ°®±±¾©
"
print
 len(a), a
#
 °Ña±àÂëΪÄÚ²¿µÄunicode, µ«ÎªÊ²Ã´·½·¨ÃûΪdecodeÄØ£¬ÎÒ
µÄÀí½âÊÇ°Ñgb2312µÄ×Ö·û´®½âÂëΪunicode

=
 look.de


Ïà¹ØÎĵµ£º

¡¶Dive Into Python¡··ÇËÀ²»¿É

ÒëÕßÑÔ£º
ÔçÔÚ 2008 Äê 8 Ô£¬ÎÒ¾ÍÔøÔÚ×Ô¼ºµÄ²©¿Í·¢±íÁËһƪ¡¶ÎªÊ²Ã´<Dive into Python>²»ÖµµÃÍƼö¡·£¨http://blog.csdn.net/lanphaday/archive/2008/08/28/2845258.aspx
£©£¬µ±Ê±ÒýÆðµÄÌÖÂ۾Ͳ»¶à˵ÁË£¬²»¹ýÊÂʵÉϵ½½ñÌìÈÔÈ»ÓÐÐí¶àÅóÓÑÁôÑÔÓëÎÒÌÖÂÛ£¬ÈÃÎÒ¼¸´ÎÔôÐIJ»ËÀ£¬ÏëдÔÙÉîÈëÅúÅС£ºÃÔ˵ÄʱºòÔÚÎÒÕæÕýÔÜ×㶯Á ......

python ±Ê¼Ç for loop and extend, append

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ÕªÒª

Ó¢ÎÄ°æDive in python¿ÉÒÔÔÚÏÂÃæÕÒµ½ÖÐÎÄ·­Òëhttp://linuxtoy.org/docs/dip/toc/index.html
Ä£¿éµÄ__name__£¬µ±Ä£¿é±»importʱ£¬ÆäΪģ¿éµÄÃû×Ö£¬µ±Ä£¿é×÷ΪmainÖ´ÐеÄʱºò£¬ÆäΪ__main__
´ÊµäµÄkeyÊÇ´óСдÃô¸ÐµÄ¡£
ListÒ²Ö§³ÖÖØÔØ+²Ù×÷£¬ÓÃÓÚ½«Á½¸ölistÁ¬½ÓÆðÀ´£¬²¢·µ»ØÒ»¸öList£¬Òò´ËËüûÓÐextendedÖ´ÐиßЧ¡£listÒ²+ ......

[Ô­´´]Python(pysvn)ÌáÈ¡svn°æ±¾¼ä¸Ä¶¯ÎļþÁбí

[Ô­´´]Python(pysvn)ÌáÈ¡svn°æ±¾¼ä¸Ä¶¯ÎļþÁбí
by AKara 2010.04.29 @ http://blog.csdn.net/akara @ akaras@163.com
---------------------------------------------------------------------
 
  Ï£ÍûʵÏÖÒ»¸öÌáÈ¡Á½¸ösvn revision¼äÓб䶯(Ôö/ɾ/¸Ä)µÄÎļþµÄÁбí
µÄÃüÁîÐй¤¾ß£»¿ÉÒÔ°ïÎÒÃÇÏîÄ¿×öһЩÁ÷ ......

pythonÖÐpackage»úÖƵÄÁ½ÖÖʵÏÖ·½Ê½


µ±Ö´ÐÐimport
moduleʱ£¬½âÊÍÆ÷»á¸ù¾ÝÏÂÃæµÄËÑË÷·¾¶£¬ËÑË÷module1.pyÎļþ¡£
1) µ±Ç°¹¤×÷Ŀ¼
2) PYTHONPATHÖеÄĿ¼
3) Python°²×°Ä¿Â¼
(/usr/local/lib/python)
ÊÂʵÉÏ£¬Ä£¿éËÑË÷ÊÇÔÚ±£´æÔÚsys.pathÕâ¸öÈ«¾Ö±äÁ¿ÖеÄĿ¼ÁбíÖнøÐÐËÑË÷¡£
sys.path»áÔÚ½âÊÍÆ÷¿ªÊ¼Ö´ÐÐʱ±»³õʼ»¯³É°üº¬£º
1)µ±Ç°¹¤×÷Ŀ¼
2) PYT ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ