»°ËµPython£¨Èý£©Íò¶ñµÄ±àÂë
Íò¶ñµÄ±àÂë
С²Ë¶ÔÓÚÀÏʦÉÏÒ»½Ú½²µÄ²»ÊǺÜÃ÷°×£¬ÒòΪûÓÐÒ»±¾ÊéÊǽ«ÎļþÓëwebÒ»Æð½²Êڵģ¬Ëû¾ö¶¨×Ô¼ºÌ½¾¿Ò»ÏÂËüÃÇÖ®¼äµÄ²»Í¬£º
Ê×ÏÈ£¬Ð¡²ËÔÚCÅ̽¨ÁËÒ»¸öÎı¾Îĵµ file.txt,ÊäÈëËĸö×Ö£ºÎÒÊÇС²Ë¡£
È»ºó£¬Ð¡²ËÔÚshellÖÐÁ·Ï°ÆðÀ´£º
>>> file=open("c:\\file.txt","r")
>>> data=file.read()
>>> print(data)
ÎÒÊÇС²Ë
>>>
С²ËÓÐÁ˳ɾ͸У¬½Ó×ÅÊÔÒ»ÊÔÕâ¸ö£º
>>> import urllib.request
>>> page=urllib.request.urlopen("http://www.baidu.com")
>>> data=page.read()
>>> print(data)
b'<!doctype html><html><head><meta http-equiv="Content-Type" content="text/html;charset=gb2312"><title>\xb0\xd9\xb6\xc8\xd2\xbb\xcf\xc2\xa3\xac\xc4\xe3\xbe\xcd\xd6\xaa\xb5\xc0
#ÔÚÕâÀïΪÁ˽ÚԼƪ·ùÎÒÊ¡ÂÔÁ˺óÃæÄÚÈÝ
“²»¶Ô°¡£¬ÕâЩ·´Ð±¸ÜÊÇɶ°¡£¡ºº×ÖզûÁË£¿”С²Ë¶ÔÓÚÕâÖÖÃïÊÓººÓïµÄÐÐΪ·Ç³£·ß¿®£¬“¹Ö²»µÃÖйúÈ˱à³Ì²»ÐÐÁË£¬Á¬ºº×Ö¶¼ÒªÕÛÌÚ°ëÌì¡£”
µÚ¶þÌìÒ»ÉϿΣ¬Ð¡²ËÅܵ½ÀÏʦ¸úÇ°£¬±§Ô¹ÆðÀ´£º“ÎļþºÍÍøÂç¶ÁÈ¡µÄ½á¹û²»Ò»Ñù°¡£¡Ò»¸öÕý³££¬Ò»¸ö²»ÏÔʾºº×Ö¡£”
´óÅ£ÀÏʦЦ×Å˵£º“Õâ²»ÄܹÖÄ㣬ÊÇÎÒûÓн²Çå³þ¡£”
Python 3.x ÓëPython 2.xµÄ²»Í¬µãÖ®Ò»¾ÍÊÇPython3kÒýÈëÁËbytes¶ÔÏ󣬸ղÅС²ËÔÚfileÖеõ½µÄÊÇstring£¨×Ö·û´®£©£¬¶øÔÚurlÖеõ½µÄÊÇbytes£¨×Ö½Ú£©¡£ÔÚ×îºóµÄÊä³öÀǰÃæÓÐÒ»¸öb£¬Ö¸µÄ¾ÍÊÇbytes¡£Æäʵ£¬Èç¹ûopen²ÉÓÓb”ģʽµÄʱºò£¬µÃµ½µÄÒ²ÊÇbytes£¬½«×Ö½Úת»¯¾ÍҪѧµ½½ñÌìµÄÄÚÈÝ£º±àÂë¡£
Python3kÖвÉÓÃÁ½¸öº¯ÊýÍê³ÉÕâ¸ö¹¤×÷£ºencode()ºÍdecode()¡£
¹ËÃû˼Ò壺encode()ÊǽøÐбàÂëµÄ£¬½«×Ö·û´®±àÂë³ÉÏëÒªµÄ±àÂë¸ñʽ¡£
decode()ÊǽøÐнâÂëµÄ£¬½«±àÂëµÄ×Ö½Ú½âÂëΪ×Ö·û´®¡£
³£ÓõıàÂë¸ñʽÓÐASCII¡¢unicode¡¢UTF-8¡¢big5¡¢gbk¡¢gb2312µÈ£¬asciiÓÃÓÚ±±ÃÀ×Ö·û£¬utf-8¡¢unicodeÊǹú¼Ê±ê×¼£¬big5ÊÇÖÐÎÄ·±Ì壬gbk¡¢gb2312ÊǼòÌåÖÐÎÄ¡£
С²ËµÄwebÊý¾ÝÊÇgb2312±àÂëµÄ£¬¿ÉÒÔÔÚºóÃæд
>>> content=data.decode('gb2312')
>>> print(content)
<!doctype html><html><head><meta http-equiv="Content-Type" content="text/html;charset=gb2312"><title>°Ù¶Èһϣ¬Äã¾ÍÖªµÀ </title>
Ïà¹ØÎĵµ£º
#coding=utf-8
from math import sqrt,cos,sin
import Image, ImageDraw
class SpireShape(object):
def __init__(self, draw):
self.draw = draw
self.line_width = 1
& ......
There should be one—--and preferably only one –--obvious way to do it.
......
¶ÔÓÚ¸öÈ˰棬ʹÓÃÁË.NET£¬°²×°ÍêÆóÒµ°æºó£¬¿´ÁË¿´Ä¿Â¼£¬·¢ÏÖ´óÁ¿python½Å±¾¡£dllÖÐÒ²ÓÐsqlite3.dll
C:\Program Files\China Mobile\EfetionĿ¼ÏÂÎļþ£º
Addin
boost_python.dll
bz2.pyd
dbghelp.dll
EFetion.exe
EFetion.exe.manifest
EFWP.exe
EFXLiveUpdate.exe
EFXLiveUpdate.exe.manifest
Face
Help.chm
......
from: http://www.cnblogs.com/jimnox/archive/2009/12/08/tips-to-python-challenge.html
Python ChallengeÊÇÒ»¸öÍøÒ³´³¹ØÓÎÏ·£¬Í¨¹ýһЩÌáʾÕÒ³öÏÂÒ»¹ØµÄÍøÒ³µØÖ·¡£ÓëÖÚ²»Í¬µÄÊÇ£¬ËüÊÇרÃÅΪ³ÌÐòÔ±Éè¼ÆµÄ£¬ÒòΪ´ó¶àÊý¹Ø¿¨¶¼Òª±à³ÌÀ´ËãŶ£¡£¡
È¥ÄêºÍͬѧһÆðÍæµÄ£¬Ëû×öÁË´ó°ë£¬ÎÒ×öÁËС°ë£¬×÷±×ÁËһЩ£¬33¹Øȫͨ£¬½ ......