Dive Into Python 3, r867 (2010)

Dive Into Python 3, r867 (2010)

ID:32366293

大小:2.52 MB

页数:489页

时间:2019-02-03

Dive Into Python 3, r867 (2010)_第1页
Dive Into Python 3, r867 (2010)_第2页
Dive Into Python 3, r867 (2010)_第3页
Dive Into Python 3, r867 (2010)_第4页
Dive Into Python 3, r867 (2010)_第5页
资源描述:

《Dive Into Python 3, r867 (2010)》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库

1、CHAPTER-1.WHAT’SNEWIN“DIVEINTOPYTHON3”❝Isn’tthiswherewecamein?❞—PinkFloyd,TheWall-1.1.A.K.A.“THEMINUSLEVEL”AreyoualreadyaPythonprogrammer?Didyoureadtheoriginal“DiveIntoPython”,ormaybeevenbuyitonpaper?(Thanks!)AreyoureadytotaketheplungeintoPython3?…Ifso,readon.(Ifnoneofthatistrue,you’dbebetteroffstar

2、tingatthebeginning.)Python3comeswithascriptcalled2to3.Learnit.Loveit.Useit.PortingCodetoPython3with2to3isareferenceofallthethingsthatthe2to3toolcanfixautomatically.Sincealotofthosethingsaresyntaxchanges,it’sagoodstartingpointtolearnaboutalotofthesyntaxchangesinPython3.(printisnowafunction,`x`doesn’t

3、work,&c.)CaseStudy:PortingchardettoPython3documentsmy(ultimatelysuccessful)efforttoportanon-triviallibraryfromPython2toPython3.Itmayhelpyou;itmaynot.There’safairlysteeplearningcurve,sinceyouneedtokindofunderstandthelibraryfirst,soyoucanunderstandwhyitbrokeandhowIfixedit.Alotofthebreakagecentersaroun

4、dstrings.Speakingofwhich…Strings.Whew.Wheretostart.Python2had“strings”and“Unicodestrings.”Python3has“bytes”and“strings.”Thatis,allstringsarenowUnicodestrings,andifyouwanttodealwithabagofbytes,youusethenewbytestype.Python3willneverimplicitlyconvertbetweenstringsandbytes,soifyou’renotsurewhichoneyouha

5、veatanygivenmoment,yourcodewillalmostcertainlybreak.ReadtheStringschapterformoredetails.Bytesvs.stringscomesupagainandagainthroughoutthebook.1•InFiles,you’lllearnthedifferencebetweenreadingfilesin“binary”and“text”mode.Reading(andwriting!)filesintextmoderequiresanencodingparameter.Sometextfilemethods

6、countcharacters,butothermethodscountbytes.Ifyourcodeassumesthatonecharacter==onebyte,itwillbreakonmulti-bytecharacters.•InHTTPWebServices,thehttplib2modulefetchesheadersanddataoverHTTP.HTTPheadersarereturnedasstrings,buttheHTTPbodyisreturnedasbytes.•InSerializingPythonObjects,you’lllearnwhythepickle

7、moduleinPython3definesanewdataformatthatisbackwardlyincompatiblewithPython2.(Hint:it’sbecauseofbytesandstrings.)AlsoJSON,whichdoesn’tsupportthebytestypeatall.I’llshowyouhowtohackaroundthat.•InCasestud

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。