Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö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ÖÐÖ´ÐÐ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_¸´ÔÓÊý¾ÝÀàÐÍ
pythonÖÐÔ­ÉúµÄ¶ÓÁÐÓÐ2ÖÖ£¬Ò»ÖÖÊÇÆÕͨµÄ¶ÓÁÐ(Queue)£¬Ò»ÖÖ½Ð×öÓÅÏȶÓÁÐ(PriorityQueue)£¬¼´Ð¡µÄÏȳöÁС£
×¢Ò⣺¶ÓÁÐÊÇḬ̈߳²È«µÄ£¬python 3.0ÖÐÖ§³Ö¶à½ø³Ì£¬Ò²ÓÐÀàËƵÄQueue£¬µ«²»ÊÇÕâ¸ö¡£
1Õ»¡¢¶ÓÁС¢¶Ñ
  pythonÖÐÔ­ÉúµÄ¶ÓÁÐÓÐ2ÖÖ£¬Ò»ÖÖÊÇÆÕͨµÄ¶ÓÁÐ(Queue)£¬Ò»ÖÖ½Ð×öÓÅÏȶÓÁÐ(PriorityQueu ......

python ÖдøÐǺźÍË«ÐǺõIJÎÊý


µ±ÒªÊ¹º¯Êý½ÓÊÕÔª×é»ò×ÖµäÐÎʽµÄ²ÎÊýµÄʱºò£¬ÓÐÒ»ÖÖÌØÊâµÄ·½·¨£¬Ëü·Ö±ðʹÓÃ*ºÍ**ǰ׺¡£ÕâÖÖ·½·¨ÔÚº¯ÊýÐèÒª»ñÈ¡¿É±äÊýÁ¿µÄ²ÎÊýµÄʱºòÌرðÓÐÓá£
>>> def powersum(power, *args):
...      '''Return the sum of each argument raised to specified power.'''
...    ......

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ºÅ