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
Ïà¹ØÎĵµ£º
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ÖÖ£¬Ò»ÖÖÊÇÆÕͨµÄ¶ÓÁÐ(Queue)£¬Ò»ÖÖ½Ð×öÓÅÏȶÓÁÐ(PriorityQueue)£¬¼´Ð¡µÄÏȳöÁС£
×¢Ò⣺¶ÓÁÐÊÇḬ̈߳²È«µÄ£¬python 3.0ÖÐÖ§³Ö¶à½ø³Ì£¬Ò²ÓÐÀàËÆµÄQueue£¬µ«²»ÊÇÕâ¸ö¡£
1Õ»¡¢¶ÓÁС¢¶Ñ
pythonÖÐÔÉúµÄ¶ÓÁÐÓÐ2ÖÖ£¬Ò»ÖÖÊÇÆÕͨµÄ¶ÓÁÐ(Queue)£¬Ò»ÖÖ½Ð×öÓÅÏȶÓÁÐ(PriorityQueu ......
¿´×ÅÍøÉÏ×¥È¡ÍøÒ³Êý¾ÝµÄÎÄÕÂÖ±µÉÑÛ
ºóÀ´Ïëµ½ÓÃ×Ö·û´®·Ö¸îÀ´ÌáÈ¡ÏàÓ¦²¿·ÖµÄÄÚÈÝ
³ÌÐò¼òµ¥£¬µ«ÊýÐÐÊýºÍϱê·ÑÁ˺ܳ¤Ê±¼ä
ÎÒÖªµÀÕâ¿Ï¶¨²»ÊÇ×îºÃµÄ°ì·¨- -!!
µ«ÎÒʵÏÖÁË£¬¹þ¹þ
# -*- coding: cp936 -*-
from urllib import *
import re
def stockSearch():
baseurl="http://www.google.cn/financ ......
1.»¥ÁªÍø£ºÓÖÒôÒë“ÒòÌØÍø”»òÕß“Ó¢ÌØÍø”£¬ÊÇÖ¸ÔÚARPAÍø»ù´¡ÉÏ·¢Õ¹³öµÄÊÀ½çÉÏ×î´óµÄÈ«ÇòÐÔ»¥ÁªÍøÂç¡£
2.Óйػ¥ÁªÍøµÄÐÒé¿ÉÒÔ·ÖΪ3²ã£º
×îµ×²ãµÄÊÇIPÐÒ飬ÊÇÓÃÓÚ±¨ÎĽ»»»ÍøÂçµÄÒ»ÖÖÃæÏòÊý¾ÝµÄÐÒ飬ÕâÒ»ÐÒ鶨ÒåÁËÊý¾Ý°üÔÚÍø¼Ê´«ËÍʱµÄ¸ñʽ¡£
ÉÏÒ»²ãÊÇUDPÐÒéºÍTCPÐÒ飬ËüÃÇÓÃÓÚ¿ØÖÆÊý¾ÝÁ÷µÄ´«Ê ......