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

PythonµÄASCII, GB2312, Unicode , UTF 8

PythonµÄASCII, GB2312, Unicode , UTF-8
ASCII ÊÇÒ»ÖÖ×Ö·û¼¯,°üÀ¨´óСдµÄÓ¢ÎÄ×Öĸ¡¢Êý×Ö¡¢¿ØÖÆ×Ö·ûµÈ£¬ËüÓÃÒ»¸ö×Ö½Ú±íʾ£¬·¶Î§ÊÇ 0-127 Unicode·ÖΪUTF-8ºÍUTF-16¡£
UTF-8±ä³¤¶ÈµÄ£¬×î¶à 6 ¸ö×Ö½Ú£¬Ð¡ÓÚ 127 µÄ×Ö·ûÓÃÒ»¸ö×Ö½Ú±íʾ£¬Óë ASCII ×Ö·û¼¯µÄ½á¹ûÒ»Ñù£¬ASCII ±àÂëϵÄÓ¢ÓïÎı¾²»ÐèÒªÐ޸ľͿÉÒÔµ±×÷ UTF-8 ±àÂë½øÐд¦Àí¡£
Python ´Ó 2.2 ¿ªÊ¼Ö§³Ö Unicode £¬º¯Êý decode( char_set )¿ÉÒÔʵÏÖ ÆäËü±àÂëµ½ Unicode µÄת»»£¬º¯Êý encode( char_set )ʵÏÖ Unicode µ½ÆäËü±àÂ뷽ʽµÄת»»¡£
±ÈÈç
("ÄãºÃ").decode( "GB2312")
½«µÃµ½
u'\u4f60\u597d'£¬
¼´ "Äã"ºÍ“ºÃ"µÄ Unicode Âë·Ö±ðÊÇ 0x4f60 ºÍ 0x597d
ÔÙÓÃ
(u'\u4f60\u597d').encode("UTF-8")
½«µÃµ½
'\xe4\xbd\xa0\xe5\xa5\xbd'
ËüÊÇ “ÄãºÃ”µÄUTF-8±àÂë½á¹û¡£
pythonÖÐʹÓà unicodeµÄ¹Ø¼ü£ºunicodeÊÇÒ»¸öÀ࣬º¯Êýunicode(str,"utf8")´Óutf8±àÂ루µ±È»Ò²¿ÉÒÔÊDZðµÄ±àÂ룩µÄ×Ö·û´®strÉú³É unicodeÀàµÄ¶ÔÏ󣬶øº¯Êýunc.encode("utf8")½«unicodeÀàµÄ¶ÔÏóuncת»»Îª£¨±àÂëΪ£©utf8±àÂ루µ±È»Ò²¿ÉÒÔÊDZðµÄ±àÂ룩µÄ×Ö·û´®¡£ÓÚÊÇ£¬±àдunicodeÏà¹Ø³ÌÐò£¬ÐèÒª×öµÄÊÂÇéÊÇ * »ñÈ¡Êý¾Ý£¨×Ö·û´®£©Ê±£¬ÓÃunicode(str, "utf8")Éú³Éunicode¶ÔÏó * ÔÚ³ÌÐòÖнöʹÓÃunicode¶ÔÏ󣬶ԳÌÐòÖгöÏÖµÄ×Ö·û´®³£Á¿¶¼ÒÔu"×Ö·û´®"µÄÐÎʽÊéд * Êä³öʱ£¬¿É½«unicode¶ÔÏóת»»ÎªÈÎÒâ±àÂëÊä³ö£¬Ê¹ÓÃstr.encode("some_encoding")
>>> unicode("ÄãºÃ", "utf8")
       u'\u4f60\u597d'
>>> x = _
>>> type(x)
>>> type("ÄãºÃ")
>>> x.encode("utf8")
       '\xe4\xbd\xa0\xe5\xa5\xbd'
>>> x.encode("gbk")
       '\xc4\xe3\xba\xc3'
>>> x.encode("gb2312")
       '\xc4\xe3\xba\xc3'
>>> print x
       ÄãºÃ
>>> print x.encode("utf8")
       ÄãºÃ
>>> print x.encode("gbk")
       ???
ÒÔÉÏÊDzâÊÔ½á¹û£¨Ubuntu 6.06£¬localeΪutf8£©£¬×¢Òâtype(x)ºÍtype("ÄãºÃ")µÄÇø±ð¡£´Ó±àÂëÉÏ¿ÉÒÔ¿´³öutf8±àÂëÓëgbk²»Í¬¡£ÔÚutf


Ïà¹ØÎĵµ£º

Ñ¡ÔñÔĶÁPythonÔ´ÂëÀ´½øÒ»²½Ìá¸ßËã·¨

×î½üÔÚÑжÁPythonÔ´ÂëÆÊÎöÒ»Ê飬´ËÊéÏ൱²»´í£¬Èç¹û×Ô¼º³å¶¯µÄÈ¥·ÖÎöPythonÔ´Âë¿ÉÄܻᵽ´¦Åö“±Ç”£¬¿´µ½´ËÊéʱÊÇ09Ä꣬ÄÇʱΪÁËÑо¿ÄÚ´æ»úÖÆ²Å·¢ÏÖÓÐÕâôһ±¾Ê飬µ«Êǹ¤×÷̫棬¸ù±¾Ã»Ê±¼äÈ¥·ÖÎöÔ´Â룬µ½ÁË2010Ä꣬ÕâÊǷdz£ÓÐÉîÖØÒâÒåµÄÒ»Ä꣬ËùÒÔÕâÒ»ÄêÒ»¶¨Òª±È֮ǰ×öµÄ»¹Òª¸¶³ö¸ü¶à£¬ÒªÏë³ÉΪ¼¼Êõ¶¥¼â¾Í±ØÐëÑÐ ......

PythonÖÐÖ´ÐÐshellÃüÁîµÄʵÀý

1¡£
myCoolVariable="some_string"
os.system("echo myCoolVariable")
2.
>>> os.system('echo "asdg"')
asdg
0
>>> os.system("echo 'asdgwere'")
asdgwere
0
3.
$ python
>>>hamburger="potato"
>>>import os
>>>os.system("echo 'hamburger'")
potato
0
......

¶Á×ÄľÄñÉçÇø¡¶¿É°®µÄpython¡·

×î½ü¿´¿É°®µÄpython£¬ÀïÃæÓкܶàÒÔǰûÓÐ×¢ÒâµÄ¶«Î÷¡£ÊéÊǽèµÄ£¬ÆÚ´ýµ½2ÔÂ27ºÅ£¬ÉçÇø½â³ýͼÊ龲Ĭ¡£
ͼÊé´ó¸Å·ÖÁË3¸ö²¿·Ö¡£µÚÒ»²¿·ÖÖ÷ÒªÊDZ¾µØ±à³ÌµÄ¹ý³Ì£¬µÚ¶þ²¿·ÖÖ÷ÒªÊÇÍøÒ³±à³Ì¡£µÚÈý²¿·ÖÊÇСֽÌõ£¬
ÌṩÁ˺ܶà֪ʶµãµÄËټǡ£
ÒÔǰҲÉϹýwoodpecker£¬ÕýÈçÍøÕ¾ÉÏдµÄ£¬È·ÊµºÜÂÒ¡£ÎÒ¾­³£²»ÖªµÀ¿´ÄÄ£¬Õâ¸öÖ»Äܶà¹ä¡£ÊéÖÐ ......

pythonµÄwebÆôº½

1.»¥ÁªÍø£ºÓÖÒôÒë“ÒòÌØÍø”»òÕß“Ó¢ÌØÍø”£¬ÊÇÖ¸ÔÚARPAÍø»ù´¡ÉÏ·¢Õ¹³öµÄÊÀ½çÉÏ×î´óµÄÈ«ÇòÐÔ»¥ÁªÍøÂç¡£
2.Óйػ¥ÁªÍøµÄЭÒé¿ÉÒÔ·ÖΪ3²ã£º
×îµ×²ãµÄÊÇIPЭÒ飬ÊÇÓÃÓÚ±¨ÎĽ»»»ÍøÂçµÄÒ»ÖÖÃæÏòÊý¾ÝµÄЭÒ飬ÕâһЭÒ鶨ÒåÁËÊý¾Ý°üÔÚÍø¼Ê´«ËÍʱµÄ¸ñʽ¡£
ÉÏÒ»²ãÊÇUDPЭÒéºÍTCPЭÒ飬ËüÃÇÓÃÓÚ¿ØÖÆÊý¾ÝÁ÷µÄ´«Ê ......

UltraEdit»·¾³pythonÓï·¨¸ßÁÁÉèÖÃ

ÎÒÒ»Ö±ÔÚÓÃultraedit¿´zope3µÄÔ´´úÂë.Óï·¨¸ßÁÁÉèÖÿɲο¼www.ultraedit.com
UltraEditÊÇÒ»¸öºÜºÃµÄ¹¤¾ß£¬µ«ÊÇĬÈϲ»Ö§³ÖPythonµÄÓï·¨¸ßÁÁ£¬ÏÂÃæÊÇÒ»¸öÏֳɵÄWordFileƬ¶Ï£¬°ÑÕâ¶ÎÎÄ×ÖCopyµ½UltraEditÏÂÃæµÄWORDFIL E.TXTÎļþÖУ¬±£´æºó¾Í¿ÉÒÔ¿´µ½UltraEdit¶ÔPythonÎļþºÍÓï·¨µÄÖ§³ÖÁË^_^£¨×¢Ò⣬°Ñ/L11¸ÄΪÄãµÄWordfileµÄ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ