Python¡¢UnicodeºÍÖÐÎÄ[ת]
¹Ø¼ü×Ö: python
Python¡¢UnicodeºÍÖÐÎÄ[ת]
pythonµÄÖÐÎÄÎÊÌâÒ»Ö±ÊÇÀ§ÈÅÐÂÊÖµÄÍ·ÌÛÎÊÌ⣬ÕâÆªÎÄÕ½«¸øÄãÏêϸµØ½²½âÒ»ÏÂÕâ·½ÃæµÄ֪ʶ¡£µ±È»£¬¼¸ºõ¿ÉÒÔÈ·¶¨µÄÊÇ£¬ÔÚ½«À´µÄ°æ±¾ÖУ¬python»á³¹µ×½â¾ö´ËÎÊÌ⣬²»ÓÃÎÒÃÇÕâôÂé·³ÁË¡£
ÏÈÀ´¿´¿´pythonµÄ°æ±¾£º
>>> import sys
>>> sys.version
'2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit (Intel)]'
£¨Ò»£©
ÓüÇʱ¾´´½¨Ò»¸öÎļþChineseTest.py£¬Ä¬ÈÏANSI£º
s = "ÖÐÎÄ"
print s
²âÊÔÒ»ÏÂÇÆÇÆ£º
E:\Project\Python\Test>python ChineseTest.py
File "ChineseTest.py", line 1
SyntaxError: Non-ASCII character '\xd6' in file ChineseTest.py on line 1, but no encoding declared; see http://www.pytho
n.org/peps/pep-0263.html for details
͵͵µØ°ÑÎļþ±àÂë¸Ä³ÉUTF-8£º
E:\Project\Python\Test>python ChineseTest.py
File "ChineseTest.py", line 1
SyntaxError: Non-ASCII character '\xe4' in file ChineseTest.py on line 1, but no encoding declared; see http://www.pytho
n.org/peps/pep-0263.html for details
ÎÞ¼ÃÓÚÊ¡£¡£¡£
¼ÈÈ»ËüÌṩÁËÍøÖ·£¬ÄǾͿ´¿´°É¡£¼òµ¥µØä¯ÀÀһϣ¬ÖÕÓÚÖªµÀÈç¹ûÎļþÀïÓзÇASCII×Ö·û£¬ÐèÒªÔÚµÚÒ»ÐлòµÚ¶þÐÐÖ¸¶¨±àÂëÉùÃ÷¡£°ÑChineseTest.pyÎļþµÄ±àÂëÖØÐ¸ÄΪANSI£¬²¢¼ÓÉϱàÂëÉùÃ÷£º
# coding=gbk
s = "ÖÐÎÄ"
print s
ÔÙÊÔһϣº
E:\Project\Python\Test>python ChineseTest.py
ÖÐÎÄ
Õý³£¿©£º£©
£¨¶þ£©
¿´Ò»¿´ËüµÄ³¤¶È£º
# coding=gbk
s = "ÖÐÎÄ"
print len(s)
½á¹û£º4¡£
sÕâÀïÊÇstrÀàÐÍ£¬ËùÒÔ¼ÆËãµÄʱºòÒ»¸öÖÐÎÄÏ൱ÓÚÁ½¸öÓ¢ÎÄ×Ö·û£¬Òò´Ë³¤¶ÈΪ4¡£
ÎÒÃÇÕâÑùд:
# coding=gbk
s = "ÖÐÎÄ"
s1 = u"ÖÐÎÄ"
s2 = unicode(s, "gbk") #Ê¡ÂÔ²ÎÊý½«ÓÃpythonĬÈϵÄASCIIÀ´½âÂë
s3 = s.decode("gbk") #°Ñstrת»»³ÉunicodeÊÇdecode£¬unicodeº¯Êý×÷ÓÃÓëÖ®Ïàͬ
print len(s1)
print len(s2)
print len(s3)
½á¹û£º 
Ïà¹ØÎĵµ£º
Python£¬¼òµ¥µÄÁ¦Á¿
¶¹°êÍø¶Ô»¥ÁªÍøÓû§À´ËµÊÇÖªÃûµÄWeb 2.0ÉçÇø£¬µ«¶Ô¿ª·¢Õß¶øÑÔ£¬¸üÖØÒªµÄÊÇÒ»¸öÓ¦ÓÃPython´òÔìµÄ·Ç³£³É¹¦µÄWeb 2.0Õ¾µã¡£
Pythonµ®ÉúÒÑÓÐ20ÄêµÄÀúÊ·£¬Ä¿Ç°¹úÄÚµÄPython·¢Õ¹×´¿öÈçºÎ£¿ÓëÆäËûÓïÑÔ£¨Æ½Ì¨£©Ïà±È£¬PythonÓÐÄÄЩÏÔ¶øÒ×¼ûµÄÓŵ㣿¶¹°êÓ¦ÓÃPython½øÐÐWeb¿ª·¢ÓÐÄÄЩ³É¹¦¾Ñé¿ÉÒÔ½è¼ø£¿´ø×ÅÕâЩΠ......
#from pp3e Chapter 9.3
#############################################################################
# popup three new window, with style
# destroy() kills one window, quit() kills all windows and app; top-level
# windows have title, icon, iconify/deiconify and protocol for wm events;
# there ......
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 ......
Ó¢ÎİæDive in python¿ÉÒÔÔÚÏÂÃæÕÒµ½ÖÐÎÄ·Òëhttp://linuxtoy.org/docs/dip/toc/index.html
Ä£¿éµÄ__name__£¬µ±Ä£¿é±»importʱ£¬ÆäΪģ¿éµÄÃû×Ö£¬µ±Ä£¿é×÷ΪmainÖ´ÐеÄʱºò£¬ÆäΪ__main__
´ÊµäµÄkeyÊÇ´óСдÃô¸ÐµÄ¡£
ListÒ²Ö§³ÖÖØÔØ+²Ù×÷£¬ÓÃÓÚ½«Á½¸ölistÁ¬½ÓÆðÀ´£¬²¢·µ»ØÒ»¸öList£¬Òò´ËËüûÓÐextendedÖ´ÐиßЧ¡£listÒ²+ ......