Example: dental hygienist

C -1. WHAT S NEW IN “DIVE INTO PYTHON 3”

SNEWIN DIVEINTOPYTHON3 Isn tthiswherewecamein? PinkFloyd, THEMINUSLEVEL Youreadtheoriginal DiveIntoPython andmaybeevenboughtitonpaper.(Thanks!) ,readon.(Ifnoneofthatistrue,you dbebetteroffstartingatthebeginning.) ,it sagoodstartingpointtolearnaboutalotofthe syntaxchangesinPython3.(printisnowafunct ion,`x`doesn twork,&c.)CaseStudy:PortingchardettoPyth on3documentsmy(ultimatelysuccessful) ; safairlysteeplearningcurve,sinceyouneedt okindofunderstandthelibraryfirst, strings and Unicodestrings. Python3has bytes and strings. Thatis,allstringsarenowUnicodestrings,an difyouwanttodealwithabagofbytes, ,soifyou renotsurewhichoneyouhaveatanygivenmoment , InFiles,you lllearnthedifferencebetweenreadingfilesi n binary and text (andwriting!)

C. HAPTER. 0. I. NSTALLING. P. YTHON Tempora mutantur nos et mutamur in illis. (Times change, and we change with them.) — ancient Roman proverb. 0.1.

Tags:

  Python, Into, Dive, Dive into python

Information

Domain:

Source:

Link to this page:

Please notify us if you found a problem with this document:

Other abuse

Advertisement

Transcription of C -1. WHAT S NEW IN “DIVE INTO PYTHON 3”

1 SNEWIN DIVEINTOPYTHON3 Isn tthiswherewecamein? PinkFloyd, THEMINUSLEVEL Youreadtheoriginal DiveIntoPython andmaybeevenboughtitonpaper.(Thanks!) ,readon.(Ifnoneofthatistrue,you dbebetteroffstartingatthebeginning.) ,it sagoodstartingpointtolearnaboutalotofthe syntaxchangesinPython3.(printisnowafunct ion,`x`doesn twork,&c.)CaseStudy:PortingchardettoPyth on3documentsmy(ultimatelysuccessful) ; safairlysteeplearningcurve,sinceyouneedt okindofunderstandthelibraryfirst, strings and Unicodestrings. Python3has bytes and strings. Thatis,allstringsarenowUnicodestrings,an difyouwanttodealwithabagofbytes, ,soifyou renotsurewhichoneyouhaveatanygivenmoment , InFiles,you lllearnthedifferencebetweenreadingfilesi n binary and text (andwriting!)

2 , ,itwillbreakonmulti-bytecharacters. InHTTPWebServices, ,buttheHTTP bodyisreturnedasbytes. InSerializingPythonObjects,you lllearnwhythepicklemoduleinPython3define sanewdataformatthatisbackwardlyincompati blewithPython2.(Hint:it sbecauseofbytesandstrings.)AlsoJSON,whic hdoesn llshowyouhowtohackaroundthat. InCasestudy:portingchardettoPython3,it tcareaboutUnicode(ohbutyouwill),you llwanttoreadaboutstringformattinginPytho n3, ,andIunderstandthemalotbetterthanIdidfiv eyearsagowhenIwrote DiveIntoPython .Youneedtounderstandthemtoo, , ,I veaddedanappendixonSpecialMethodNames,wh ichiskindoflikethePythondocs DataModel DiveIntoPython , ,whichdoesn , ,butyoushouldavoidthem,becausetheysuck!

3 AlsonewinPython notinthelanguagebutinthecommunity istheemergenceofcoderepositorieslikeTheP ythonPackageIndex(PyPI). Temporamutanturnosetmutamurinillis.(Time schange,andwechangewiththem.) ' ,you'llinstalltheversionofPython3that' 'reusinganaccountonahostedserver, rerunningLinuxathome,youmayalreadyhavePy thon3, ; , tdespair!Youcanpoint-and-clickyourwaythr oughinstallingPython, ,lookinyourApplicationsmenuforaprogramca lledTerminal.(ItmaybeinasubmenulikeAcces soriesorSystem.)OnMacOSX, reatacommandlineprompt,justtypepython3(a lllowercase,nospaces) ,Python3isalreadyinstalled, @atlantis:~$python3 PYTHON + (r301:69556, Apr 15 2009, 17:25:52)[GCC ] on linux2 Type "help", "copyright", "credits" or "license" for more information.

4 >>>(Typeexit()andpressENTER toexitthePythoninteractiveshell.)Mywebho stingprovideralsorunsLinuxandprovidescom mand-lineaccess,butmyserverdoesnothavePy thon3installed.(Boo!)mark@manganese:~$py thon3bash: python3: command not foundSobacktothequestionthatstartedthiss ection, WhichPythonisrightforyou? Whicheveronerunsonthecomputeryoualreadyh ave.[ReadonforWindowsinstructions,orskip toInstallingonMacOSX,InstallingonUbuntuL inux,orInstallingonOtherPlatforms.] ,therearelotsofdifferentversionsofWindow s XP,Vista,Windows7 rerunning,it : (Windowsbinary doesnotincludesource)4 (WindowsAMD64binary doesnotincludesource)Idon twanttoincludedirectdownloadlinkshere,be causeminorupdatesofPythonhappenallthetim eandIdon , ,sinceyou , tacceptimitations!

5 Installforallusers, whichisthebestchoiceunlessyouhaveagoodre asontochooseotherwise.(Onepossiblereason whyyouwouldwantto installjustforme isthatyouareinstallingPythononyourcompan y scomputerandyoudon ,whyareyouinstallingPythonwithoutpermiss ionfromyourcompany sWindowsadministrator?Don tgetmeintroublehere!) , :\Python31\, ,youcanbrowsetoitusingtheembeddedcontrol s, :drive;youcaninstallitonanydrive, ,butit , ,youcanexcludecertaincomponents. RegisterExtensionsallowsyoutodouble-clic kPythonscripts(.pyfiles) (Thisoptiondoesn trequireanydiskspace,sothereislittlepoin tinexcludingit.)

6 Tcl/TkisthegraphicslibraryusedbythePytho nShell, ,youcanskipthisoption. , reunsurehowmuchdiskspaceyouhave, ,computehowmuchspaceisavailableoneachdri ve, CustomizingPython ,selectthedrop-downbuttonbeforetheoption andselect Entirefeaturewillbeunavailable. Forexample, (Thishappenssoquickly,Ihadtotryitthreeti mestoevengetascreenshotofit!) , , [SkiptousingthePythonShell] (likemostWindowsPCs). tneedtounderstandthedifference,becauseth ere , , (Ifthisdoesn thappen,you )Thediskimagecontainsanumberoftextfiles( , , ),andtheactualinstallerpackage, , (whichyoudidn tread,didyou?)

7 , , ,youcan , , , :Pythonisopensource,andyoumayuseitonanyp latform,foranypurpose, ,youmust agree ,youarereally agreeing thatthelicenseisgrantingyouadditionalrig hts, ,butduetolimitationsoftheinstaller, , , ,clicktheCustomizebutton; ,theinstallerwillpresentyouwiththefollow inglistoffeatures: ,andisbothselectedanddisabledbecauseitmu stbeinstalled. GUIA pplicationsincludesIDLE, ,too. Shellprofileupdatercontrolswhethertoupda teyourshellprofile( ) tneedtochangethis. FixsystemPythonshouldnotbechanged.(Ittel lsyourMactousePython3asthedefaultPythonf orallscripts, ,sincemostofthosescriptsarewrittenforPyt hon2,andtheywouldfailtorunproperlyunderP ython3.)

8 , , tchangetheinstalllocation, , [SkiptousingthePythonShell] , ,theeasiestwaytoinstallPython3 , ; ,000applications, Canonical-maintainedapplications, whichisasmallsubsetofthetotalnumberofapp licationsthatareofficiallysupportedbyCan onical, ,sothefirststepistodropdownthisfiltermen uandselect AllOpenSourceapplications. Onceyou vewidenedthefiltertoincludeallopensource applications, ( ). :IDLE( ). vecheckedthosetwopackages, ( )andPython( ). , , ,youcandouble-clickIDLE tolaunchthePythonShell, ,thentheProgrammingsubmenu, [SkiptousingthePythonShell] ,itisavailableinvirtuallyeveryLinux,BSD, ,RedHatLinuxusestheyumpackagemanager;Fre eBSDhasitsportsandpackagescollection; +youroperatingsystemwilltellyouwhetheraP ython3packageisavailable,andhowtoinstall it.

9 ,getinteractivehelponcommands, (namedIDLE) talreadyhaveafavoritetexteditor, ,you llseeexampleslikethis:>>>1 + 12 Thethreeanglebrackets,>>>, + tbeshy;itwon tbite!Theworstthatwillhappenisyou (onceyoupressENTER);expressionsgetevalua tedimmediately, ,1+ ,ofcourse, stryanotherone.>>>print('Hello world!')Hello world!Prettysimple,no?Butthere youcan trememberacommand,oryoucan tremembertheproperargumentstopassacertai nfunction >>>helpType help() for interactive help, or help(object) for help about , ,whereinsteadofevaluatingPythonexpressio ns, ,typehelp() >>>help()Welcome to PYTHON !

10 This is the online help this is your first time using PYTHON , you should definitely check outthe tutorial on the Internet at the name of any module, keyword, or topic to get help on writingPython programs and using PYTHON modules. To quit this help utility andreturn to the interpreter, just type "quit".To get a list of available modules, keywords, or topics, type "modules","keywords", or "topics". Each module also comes with a one-line summaryof what it does; to list the modules whose summaries contain a given wordsuch as "spam", type "modules spam".