home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / Languages / Python 1.1 / Doc / qua.tex < prev    next >
LaTeX Document  |  1994-08-08  |  58.5 KB  |  [TEXT/R*ch]

open in: MacOS 8.1     |     Win98     |     DOS

view JSON data     |     view as text

This file was processed as: LaTeX Document (document/latex).

You can browse this item here: qua.tex

ConfidenceProgramDetectionMatch TypeSupport
100% dexvert LaTeX Document (document/latex) magic Supported
1% dexvert Text File (text/txt) fallback Supported
100% file LaTeX document text default
99% file Nim source code, ASCII text, with CR line terminators default (weak)
100% checkBytes Printable ASCII default
100% perlTextCheck Likely Text (Perl) default
100% siegfried fmt/281 LaTeX (Subdocument) default
100% detectItEasy Format: plain text[CR] default (weak)


id metadata
keyvalue
macFileType[TEXT]
macFileCreator[R*ch]



hex view
+--------+-------------------------+-------------------------+--------+--------+
|00000000| 5c 64 6f 63 75 6d 65 6e | 74 73 74 79 6c 65 5b 31 |\documen|tstyle[1|
|00000010| 31 70 74 5d 7b 61 72 74 | 69 63 6c 65 7d 0d 5c 6e |1pt]{art|icle}.\n|
|00000020| 65 77 63 6f 6d 6d 61 6e | 64 7b 5c 43 70 70 7d 7b |ewcomman|d{\Cpp}{|
|00000030| 43 5c 70 72 6f 74 65 63 | 74 5c 72 61 69 73 65 62 |C\protec|t\raiseb|
|00000040| 6f 78 7b 2e 31 38 65 78 | 7d 7b 2b 2b 7d 7d 0d 0d |ox{.18ex|}{++}}..|
|00000050| 5c 74 69 74 6c 65 7b 0d | 49 6e 74 65 72 61 63 74 |\title{.|Interact|
|00000060| 69 76 65 6c 79 20 54 65 | 73 74 69 6e 67 20 52 65 |ively Te|sting Re|
|00000070| 6d 6f 74 65 20 53 65 72 | 76 65 72 73 20 55 73 69 |mote Ser|vers Usi|
|00000080| 6e 67 20 74 68 65 20 50 | 79 74 68 6f 6e 20 50 72 |ng the P|ython Pr|
|00000090| 6f 67 72 61 6d 6d 69 6e | 67 20 4c 61 6e 67 75 61 |ogrammin|g Langua|
|000000a0| 67 65 0d 7d 0d 0d 5c 61 | 75 74 68 6f 72 7b 0d 09 |ge.}..\a|uthor{..|
|000000b0| 47 75 69 64 6f 20 76 61 | 6e 20 52 6f 73 73 75 6d |Guido va|n Rossum|
|000000c0| 20 5c 5c 0d 09 44 65 70 | 74 2e 20 43 53 54 2c 20 | \\..Dep|t. CST, |
|000000d0| 43 57 49 2c 20 50 2e 4f | 2e 20 42 6f 78 20 39 34 |CWI, P.O|. Box 94|
|000000e0| 30 37 39 20 5c 5c 0d 09 | 31 30 39 30 20 47 42 20 |079 \\..|1090 GB |
|000000f0| 41 6d 73 74 65 72 64 61 | 6d 2c 20 54 68 65 20 4e |Amsterda|m, The N|
|00000100| 65 74 68 65 72 6c 61 6e | 64 73 20 5c 5c 0d 09 45 |etherlan|ds \\..E|
|00000110| 2d 6d 61 69 6c 3a 20 7b | 5c 74 74 20 67 75 69 64 |-mail: {|\tt guid|
|00000120| 6f 40 63 77 69 2e 6e 6c | 7d 0d 5c 61 6e 64 0d 09 |o@cwi.nl|}.\and..|
|00000130| 4a 65 6c 6b 65 20 64 65 | 20 42 6f 65 72 20 5c 5c |Jelke de| Boer \\|
|00000140| 0d 09 48 49 4f 20 45 6e | 73 63 68 65 64 65 3b 20 |..HIO En|schede; |
|00000150| 50 2e 4f 2e 42 6f 78 20 | 31 33 32 36 20 5c 5c 0d |P.O.Box |1326 \\.|
|00000160| 09 37 35 30 30 20 42 48 | 20 20 45 6e 73 63 68 65 |.7500 BH| Ensche|
|00000170| 64 65 2c 20 54 68 65 20 | 4e 65 74 68 65 72 6c 61 |de, The |Netherla|
|00000180| 6e 64 73 0d 7d 0d 0d 5c | 62 65 67 69 6e 7b 64 6f |nds.}..\|begin{do|
|00000190| 63 75 6d 65 6e 74 7d 0d | 0d 5c 6d 61 6b 65 74 69 |cument}.|.\maketi|
|000001a0| 74 6c 65 0d 0d 5c 62 65 | 67 69 6e 7b 61 62 73 74 |tle..\be|gin{abst|
|000001b0| 72 61 63 74 7d 0d 54 68 | 69 73 20 70 61 70 65 72 |ract}.Th|is paper|
|000001c0| 20 64 65 73 63 72 69 62 | 65 73 20 68 6f 77 20 74 | describ|es how t|
|000001d0| 77 6f 20 74 6f 6f 6c 73 | 20 74 68 61 74 20 77 65 |wo tools| that we|
|000001e0| 72 65 20 64 65 76 65 6c | 6f 70 65 64 20 71 75 69 |re devel|oped qui|
|000001f0| 74 65 0d 69 6e 64 65 70 | 65 6e 64 65 6e 74 6c 79 |te.indep|endently|
|00000200| 20 67 61 69 6e 65 64 20 | 69 6e 20 70 6f 77 65 72 | gained |in power|
|00000210| 20 62 79 20 61 20 77 65 | 6c 6c 2d 64 65 73 69 67 | by a we|ll-desig|
|00000220| 6e 65 64 20 63 6f 6e 6e | 65 63 74 69 6f 6e 20 62 |ned conn|ection b|
|00000230| 65 74 77 65 65 6e 0d 74 | 68 65 6d 2e 20 20 54 68 |etween.t|hem. Th|
|00000240| 65 20 74 6f 6f 6c 73 20 | 61 72 65 20 50 79 74 68 |e tools |are Pyth|
|00000250| 6f 6e 2c 20 61 6e 20 69 | 6e 74 65 72 70 72 65 74 |on, an i|nterpret|
|00000260| 65 64 20 70 72 6f 74 6f | 74 79 70 69 6e 67 20 6c |ed proto|typing l|
|00000270| 61 6e 67 75 61 67 65 2c | 20 61 6e 64 0d 41 49 4c |anguage,| and.AIL|
|00000280| 2c 20 61 20 52 65 6d 6f | 74 65 20 50 72 6f 63 65 |, a Remo|te Proce|
|00000290| 64 75 72 65 20 43 61 6c | 6c 20 73 74 75 62 20 67 |dure Cal|l stub g|
|000002a0| 65 6e 65 72 61 74 6f 72 | 2e 20 20 54 68 65 20 63 |enerator|. The c|
|000002b0| 6f 6e 74 65 78 74 20 69 | 73 20 41 6d 6f 65 62 61 |ontext i|s Amoeba|
|000002c0| 2c 20 61 0d 77 65 6c 6c | 2d 6b 6e 6f 77 6e 20 64 |, a.well|-known d|
|000002d0| 69 73 74 72 69 62 75 74 | 65 64 20 6f 70 65 72 61 |istribut|ed opera|
|000002e0| 74 69 6e 67 20 73 79 73 | 74 65 6d 20 64 65 76 65 |ting sys|tem deve|
|000002f0| 6c 6f 70 65 64 20 6a 6f | 69 6e 74 6c 79 20 62 79 |loped jo|intly by|
|00000300| 20 74 68 65 20 46 72 65 | 65 0d 55 6e 69 76 65 72 | the Fre|e.Univer|
|00000310| 73 69 74 79 20 61 6e 64 | 20 43 57 49 20 69 6e 20 |sity and| CWI in |
|00000320| 41 6d 73 74 65 72 64 61 | 6d 2e 0d 0d 41 73 20 61 |Amsterda|m...As a|
|00000330| 20 63 6f 6e 73 65 71 75 | 65 6e 63 65 20 6f 66 20 | consequ|ence of |
|00000340| 74 68 65 69 72 20 69 6e | 74 65 67 72 61 74 69 6f |their in|tegratio|
|00000350| 6e 2c 20 62 6f 74 68 20 | 74 6f 6f 6c 73 20 68 61 |n, both |tools ha|
|00000360| 76 65 20 70 72 6f 66 69 | 74 65 64 3a 0d 50 79 74 |ve profi|ted:.Pyt|
|00000370| 68 6f 6e 20 67 61 69 6e | 65 64 20 75 73 61 62 69 |hon gain|ed usabi|
|00000380| 6c 69 74 79 20 77 68 65 | 6e 20 75 73 65 64 20 77 |lity whe|n used w|
|00000390| 69 74 68 20 41 6d 6f 65 | 62 61 20 2d 2d 2d 20 66 |ith Amoe|ba --- f|
|000003a0| 6f 72 20 77 68 69 63 68 | 20 69 74 20 77 61 73 20 |or which| it was |
|000003b0| 6e 6f 74 0d 73 70 65 63 | 69 66 69 63 61 6c 6c 79 |not.spec|ifically|
|000003c0| 20 64 65 76 65 6c 6f 70 | 65 64 20 2d 2d 2d 20 61 | develop|ed --- a|
|000003d0| 6e 64 20 41 49 4c 20 75 | 73 65 72 73 20 6e 6f 77 |nd AIL u|sers now|
|000003e0| 20 68 61 76 65 20 61 20 | 70 6f 77 65 72 66 75 6c | have a |powerful|
|000003f0| 0d 69 6e 74 65 72 61 63 | 74 69 76 65 20 74 6f 6f |.interac|tive too|
|00000400| 6c 20 74 6f 20 74 65 73 | 74 20 73 65 72 76 65 72 |l to tes|t server|
|00000410| 73 20 61 6e 64 20 74 6f | 20 65 78 70 65 72 69 6d |s and to| experim|
|00000420| 65 6e 74 20 77 69 74 68 | 20 6e 65 77 0d 63 6c 69 |ent with| new.cli|
|00000430| 65 6e 74 2f 73 65 72 76 | 65 72 20 69 6e 74 65 72 |ent/serv|er inter|
|00000440| 66 61 63 65 73 2e 25 0d | 5c 66 6f 6f 74 6e 6f 74 |faces.%.|\footnot|
|00000450| 65 7b 0d 41 6e 20 65 61 | 72 6c 69 65 72 20 76 65 |e{.An ea|rlier ve|
|00000460| 72 73 69 6f 6e 20 6f 66 | 20 74 68 69 73 20 70 61 |rsion of| this pa|
|00000470| 70 65 72 20 77 61 73 20 | 70 72 65 73 65 6e 74 65 |per was |presente|
|00000480| 64 20 61 74 20 74 68 65 | 20 53 70 72 69 6e 67 20 |d at the| Spring |
|00000490| 31 39 39 31 0d 45 75 72 | 4f 70 65 6e 20 43 6f 6e |1991.Eur|Open Con|
|000004a0| 66 65 72 65 6e 63 65 20 | 69 6e 20 54 72 6f 6d 73 |ference |in Troms|
|000004b0| 7b 5c 6f 7d 20 75 6e 64 | 65 72 20 74 68 65 20 74 |{\o} und|er the t|
|000004c0| 69 74 6c 65 20 60 60 4c | 69 6e 6b 69 6e 67 20 61 |itle ``L|inking a|
|000004d0| 20 53 74 75 62 0d 47 65 | 6e 65 72 61 74 6f 72 20 | Stub.Ge|nerator |
|000004e0| 28 41 49 4c 29 20 74 6f | 20 61 20 50 72 6f 74 6f |(AIL) to| a Proto|
|000004f0| 74 79 70 69 6e 67 20 4c | 61 6e 67 75 61 67 65 20 |typing L|anguage |
|00000500| 28 50 79 74 68 6f 6e 29 | 2e 27 27 0d 7d 0d 5c 65 |(Python)|.''.}.\e|
|00000510| 6e 64 7b 61 62 73 74 72 | 61 63 74 7d 0d 0d 5c 73 |nd{abstr|act}..\s|
|00000520| 65 63 74 69 6f 6e 7b 49 | 6e 74 72 6f 64 75 63 74 |ection{I|ntroduct|
|00000530| 69 6f 6e 7d 0d 0d 52 65 | 6d 6f 74 65 20 50 72 6f |ion}..Re|mote Pro|
|00000540| 63 65 64 75 72 65 20 43 | 61 6c 6c 20 28 52 50 43 |cedure C|all (RPC|
|00000550| 29 20 69 6e 74 65 72 66 | 61 63 65 73 2c 20 75 73 |) interf|aces, us|
|00000560| 65 64 20 69 6e 20 64 69 | 73 74 72 69 62 75 74 65 |ed in di|stribute|
|00000570| 64 20 73 79 73 74 65 6d | 73 0d 6c 69 6b 65 20 41 |d system|s.like A|
|00000580| 6d 6f 65 62 61 0d 5c 63 | 69 74 65 7b 41 6d 6f 65 |moeba.\c|ite{Amoe|
|00000590| 62 61 3a 49 45 45 45 2c | 41 6d 6f 65 62 61 3a 43 |ba:IEEE,|Amoeba:C|
|000005a0| 41 43 4d 7d 2c 0d 68 61 | 76 65 20 61 20 6d 75 63 |ACM},.ha|ve a muc|
|000005b0| 68 20 6d 6f 72 65 20 63 | 6f 6e 63 72 65 74 65 20 |h more c|oncrete |
|000005c0| 63 68 61 72 61 63 74 65 | 72 20 74 68 61 6e 20 6c |characte|r than l|
|000005d0| 6f 63 61 6c 20 70 72 6f | 63 65 64 75 72 65 20 63 |ocal pro|cedure c|
|000005e0| 61 6c 6c 0d 69 6e 74 65 | 72 66 61 63 65 73 20 69 |all.inte|rfaces i|
|000005f0| 6e 20 74 72 61 64 69 74 | 69 6f 6e 61 6c 20 73 79 |n tradit|ional sy|
|00000600| 73 74 65 6d 73 2e 20 20 | 42 65 63 61 75 73 65 20 |stems. |Because |
|00000610| 63 6c 69 65 6e 74 73 20 | 61 6e 64 20 73 65 72 76 |clients |and serv|
|00000620| 65 72 73 20 6d 61 79 0d | 72 75 6e 20 6f 6e 20 64 |ers may.|run on d|
|00000630| 69 66 66 65 72 65 6e 74 | 20 6d 61 63 68 69 6e 65 |ifferent| machine|
|00000640| 73 2c 20 77 69 74 68 20 | 70 6f 73 73 69 62 6c 79 |s, with |possibly|
|00000650| 20 64 69 66 66 65 72 65 | 6e 74 20 77 6f 72 64 20 | differe|nt word |
|00000660| 73 69 7a 65 2c 20 62 79 | 74 65 0d 6f 72 64 65 72 |size, by|te.order|
|00000670| 2c 20 65 74 63 2e 2c 20 | 6d 75 63 68 20 63 61 72 |, etc., |much car|
|00000680| 65 20 69 73 20 6e 65 65 | 64 65 64 20 74 6f 20 64 |e is nee|ded to d|
|00000690| 65 73 63 72 69 62 65 20 | 69 6e 74 65 72 66 61 63 |escribe |interfac|
|000006a0| 65 73 20 65 78 61 63 74 | 6c 79 20 61 6e 64 20 74 |es exact|ly and t|
|000006b0| 6f 0d 69 6d 70 6c 65 6d | 65 6e 74 20 74 68 65 6d |o.implem|ent them|
|000006c0| 20 69 6e 20 73 75 63 68 | 20 61 20 77 61 79 20 74 | in such| a way t|
|000006d0| 68 61 74 20 74 68 65 79 | 20 63 6f 6e 74 69 6e 75 |hat they| continu|
|000006e0| 65 20 74 6f 20 77 6f 72 | 6b 20 77 68 65 6e 20 61 |e to wor|k when a|
|000006f0| 20 63 6c 69 65 6e 74 0d | 6f 72 20 73 65 72 76 65 | client.|or serve|
|00000700| 72 20 69 73 20 6d 6f 76 | 65 64 20 74 6f 20 61 20 |r is mov|ed to a |
|00000710| 64 69 66 66 65 72 65 6e | 74 20 6d 61 63 68 69 6e |differen|t machin|
|00000720| 65 2e 20 20 53 69 6e 63 | 65 20 6d 61 63 68 69 6e |e. Sinc|e machin|
|00000730| 65 73 20 6d 61 79 20 66 | 61 69 6c 0d 69 6e 64 65 |es may f|ail.inde|
|00000740| 70 65 6e 64 65 6e 74 6c | 79 2c 20 65 72 72 6f 72 |pendentl|y, error|
|00000750| 20 68 61 6e 64 6c 69 6e | 67 20 6d 75 73 74 20 61 | handlin|g must a|
|00000760| 6c 73 6f 20 62 65 20 74 | 72 65 61 74 65 64 20 6d |lso be t|reated m|
|00000770| 6f 72 65 20 63 61 72 65 | 66 75 6c 6c 79 2e 0d 0d |ore care|fully...|
|00000780| 41 20 63 6f 6d 6d 6f 6e | 20 61 70 70 72 6f 61 63 |A common| approac|
|00000790| 68 20 74 6f 20 73 75 63 | 68 20 70 72 6f 62 6c 65 |h to suc|h proble|
|000007a0| 6d 73 20 69 73 20 74 6f | 20 75 73 65 20 61 20 7b |ms is to| use a {|
|000007b0| 5c 65 6d 20 73 74 75 62 | 20 67 65 6e 65 72 61 74 |\em stub| generat|
|000007c0| 6f 72 7d 2e 0d 54 68 69 | 73 20 69 73 20 61 20 70 |or}..Thi|s is a p|
|000007d0| 72 6f 67 72 61 6d 20 74 | 68 61 74 20 74 61 6b 65 |rogram t|hat take|
|000007e0| 73 20 61 6e 20 69 6e 74 | 65 72 66 61 63 65 20 64 |s an int|erface d|
|000007f0| 65 73 63 72 69 70 74 69 | 6f 6e 20 61 6e 64 20 74 |escripti|on and t|
|00000800| 72 61 6e 73 66 6f 72 6d | 73 0d 69 74 20 69 6e 74 |ransform|s.it int|
|00000810| 6f 20 66 75 6e 63 74 69 | 6f 6e 73 20 74 68 61 74 |o functi|ons that|
|00000820| 20 6d 75 73 74 20 62 65 | 20 63 6f 6d 70 69 6c 65 | must be| compile|
|00000830| 64 20 61 6e 64 20 6c 69 | 6e 6b 65 64 20 77 69 74 |d and li|nked wit|
|00000840| 68 20 63 6c 69 65 6e 74 | 20 61 6e 64 0d 73 65 72 |h client| and.ser|
|00000850| 76 65 72 20 61 70 70 6c | 69 63 61 74 69 6f 6e 73 |ver appl|ications|
|00000860| 2e 20 20 54 68 65 73 65 | 20 66 75 6e 63 74 69 6f |. These| functio|
|00000870| 6e 73 20 61 72 65 20 63 | 61 6c 6c 65 64 20 62 79 |ns are c|alled by|
|00000880| 20 74 68 65 20 61 70 70 | 6c 69 63 61 74 69 6f 6e | the app|lication|
|00000890| 0d 63 6f 64 65 20 74 6f | 20 74 61 6b 65 20 63 61 |.code to| take ca|
|000008a0| 72 65 20 6f 66 20 64 65 | 74 61 69 6c 73 20 6f 66 |re of de|tails of|
|000008b0| 20 69 6e 74 65 72 66 61 | 63 69 6e 67 20 74 6f 20 | interfa|cing to |
|000008c0| 74 68 65 20 73 79 73 74 | 65 6d 27 73 20 52 50 43 |the syst|em's RPC|
|000008d0| 20 6c 61 79 65 72 2c 0d | 74 6f 20 69 6d 70 6c 65 | layer,.|to imple|
|000008e0| 6d 65 6e 74 20 74 72 61 | 6e 73 66 6f 72 6d 61 74 |ment tra|nsformat|
|000008f0| 69 6f 6e 73 20 62 65 74 | 77 65 65 6e 20 64 61 74 |ions bet|ween dat|
|00000900| 61 20 72 65 70 72 65 73 | 65 6e 74 61 74 69 6f 6e |a repres|entation|
|00000910| 73 20 6f 66 20 64 69 66 | 66 65 72 65 6e 74 0d 6d |s of dif|ferent.m|
|00000920| 61 63 68 69 6e 65 73 2c | 20 74 6f 20 63 68 65 63 |achines,| to chec|
|00000930| 6b 20 66 6f 72 20 65 72 | 72 6f 72 73 2c 20 65 74 |k for er|rors, et|
|00000940| 63 2e 20 20 54 68 65 79 | 20 61 72 65 20 63 61 6c |c. They| are cal|
|00000950| 6c 65 64 20 60 73 74 75 | 62 73 27 20 62 65 63 61 |led `stu|bs' beca|
|00000960| 75 73 65 0d 74 68 65 79 | 20 64 6f 6e 27 74 20 61 |use.they| don't a|
|00000970| 63 74 75 61 6c 6c 79 20 | 70 65 72 66 6f 72 6d 20 |ctually |perform |
|00000980| 74 68 65 20 61 63 74 69 | 6f 6e 20 74 68 61 74 20 |the acti|on that |
|00000990| 74 68 65 79 20 61 72 65 | 20 63 61 6c 6c 65 64 20 |they are| called |
|000009a0| 66 6f 72 20 62 75 74 0d | 6f 6e 6c 79 20 72 65 6c |for but.|only rel|
|000009b0| 61 79 20 74 68 65 20 70 | 61 72 61 6d 65 74 65 72 |ay the p|arameter|
|000009c0| 73 20 74 6f 20 74 68 65 | 20 73 65 72 76 65 72 0d |s to the| server.|
|000009d0| 5c 63 69 74 65 7b 52 50 | 43 7d 2e 0d 0d 41 6d 6f |\cite{RP|C}...Amo|
|000009e0| 65 62 61 27 73 20 73 74 | 75 62 20 67 65 6e 65 72 |eba's st|ub gener|
|000009f0| 61 74 6f 72 20 69 73 20 | 63 61 6c 6c 65 64 20 41 |ator is |called A|
|00000a00| 49 4c 2c 20 77 68 69 63 | 68 20 73 74 61 6e 64 73 |IL, whic|h stands|
|00000a10| 20 66 6f 72 20 41 6d 6f | 65 62 61 0d 49 6e 74 65 | for Amo|eba.Inte|
|00000a20| 72 66 61 63 65 20 4c 61 | 6e 67 75 61 67 65 0d 5c |rface La|nguage.\|
|00000a30| 63 69 74 65 7b 41 49 4c | 7d 2e 0d 54 68 65 20 66 |cite{AIL|}..The f|
|00000a40| 69 72 73 74 20 76 65 72 | 73 69 6f 6e 20 6f 66 20 |irst ver|sion of |
|00000a50| 41 49 4c 20 67 65 6e 65 | 72 61 74 65 64 20 6f 6e |AIL gene|rated on|
|00000a60| 6c 79 20 43 20 66 75 6e | 63 74 69 6f 6e 73 2c 20 |ly C fun|ctions, |
|00000a70| 62 75 74 20 61 6e 20 65 | 78 70 6c 69 63 69 74 0d |but an e|xplicit.|
|00000a80| 67 6f 61 6c 20 6f 66 20 | 41 49 4c 27 73 20 64 65 |goal of |AIL's de|
|00000a90| 73 69 67 6e 20 77 61 73 | 20 7b 5c 65 6d 20 72 65 |sign was| {\em re|
|00000aa0| 74 61 72 67 65 74 61 62 | 69 6c 69 74 79 7d 3a 20 |targetab|ility}: |
|00000ab0| 69 74 20 73 68 6f 75 6c | 64 20 62 65 20 70 6f 73 |it shoul|d be pos|
|00000ac0| 73 69 62 6c 65 0d 74 6f | 20 61 64 64 20 62 61 63 |sible.to| add bac|
|00000ad0| 6b 2d 65 6e 64 73 20 74 | 68 61 74 20 67 65 6e 65 |k-ends t|hat gene|
|00000ae0| 72 61 74 65 20 73 74 75 | 62 73 20 66 6f 72 20 64 |rate stu|bs for d|
|00000af0| 69 66 66 65 72 65 6e 74 | 20 6c 61 6e 67 75 61 67 |ifferent| languag|
|00000b00| 65 73 20 66 72 6f 6d 20 | 74 68 65 0d 73 61 6d 65 |es from |the.same|
|00000b10| 20 69 6e 74 65 72 66 61 | 63 65 20 64 65 73 63 72 | interfa|ce descr|
|00000b20| 69 70 74 69 6f 6e 73 2e | 20 20 4d 6f 72 65 6f 76 |iptions.| Moreov|
|00000b30| 65 72 2c 20 74 68 65 20 | 73 74 75 62 73 20 67 65 |er, the |stubs ge|
|00000b40| 6e 65 72 61 74 65 64 20 | 62 79 0d 64 69 66 66 65 |nerated |by.diffe|
|00000b50| 72 65 6e 74 20 62 61 63 | 6b 2d 65 6e 64 73 20 6d |rent bac|k-ends m|
|00000b60| 75 73 74 20 62 65 20 7b | 5c 65 6d 20 69 6e 74 65 |ust be {|\em inte|
|00000b70| 72 6f 70 65 72 61 62 6c | 65 7d 3a 20 61 20 63 6c |roperabl|e}: a cl|
|00000b80| 69 65 6e 74 20 77 72 69 | 74 74 65 6e 20 69 6e 0d |ient wri|tten in.|
|00000b90| 4d 6f 64 75 6c 61 2d 33 | 2c 20 73 61 79 2c 20 73 |Modula-3|, say, s|
|00000ba0| 68 6f 75 6c 64 20 62 65 | 20 61 62 6c 65 20 74 6f |hould be| able to|
|00000bb0| 20 75 73 65 20 61 20 73 | 65 72 76 65 72 20 77 72 | use a s|erver wr|
|00000bc0| 69 74 74 65 6e 20 69 6e | 20 43 2c 20 61 6e 64 20 |itten in| C, and |
|00000bd0| 76 69 63 65 0d 76 65 72 | 73 61 2e 0d 0d 54 68 69 |vice.ver|sa...Thi|
|00000be0| 73 20 69 6e 74 65 72 6f | 70 65 72 61 62 69 6c 69 |s intero|perabili|
|00000bf0| 74 79 20 69 73 20 74 68 | 65 20 6b 65 79 20 74 6f |ty is th|e key to|
|00000c00| 20 74 68 65 20 73 75 63 | 63 65 73 73 20 6f 66 20 | the suc|cess of |
|00000c10| 74 68 65 20 6d 61 72 72 | 69 61 67 65 0d 62 65 74 |the marr|iage.bet|
|00000c20| 77 65 65 6e 20 41 49 4c | 20 61 6e 64 20 50 79 74 |ween AIL| and Pyt|
|00000c30| 68 6f 6e 2e 20 20 50 79 | 74 68 6f 6e 20 69 73 20 |hon. Py|thon is |
|00000c40| 61 20 76 65 72 73 61 74 | 69 6c 65 20 69 6e 74 65 |a versat|ile inte|
|00000c50| 72 70 72 65 74 65 64 20 | 6c 61 6e 67 75 61 67 65 |rpreted |language|
|00000c60| 0d 64 65 76 65 6c 6f 70 | 65 64 20 62 79 20 74 68 |.develop|ed by th|
|00000c70| 65 20 66 69 72 73 74 20 | 61 75 74 68 6f 72 2e 20 |e first |author. |
|00000c80| 20 4f 72 69 67 69 6e 61 | 6c 6c 79 20 69 6e 74 65 | Origina|lly inte|
|00000c90| 6e 64 65 64 20 61 73 20 | 61 6e 20 61 6c 74 65 72 |nded as |an alter|
|00000ca0| 6e 61 74 69 76 65 0d 66 | 6f 72 20 74 68 65 20 6b |native.f|or the k|
|00000cb0| 69 6e 64 20 6f 66 20 6f | 64 64 20 6a 6f 62 73 20 |ind of o|dd jobs |
|00000cc0| 74 68 61 74 20 61 72 65 | 20 74 72 61 64 69 74 69 |that are| traditi|
|00000cd0| 6f 6e 61 6c 6c 79 20 73 | 6f 6c 76 65 64 20 62 79 |onally s|olved by|
|00000ce0| 20 61 20 6d 69 78 74 75 | 72 65 20 6f 66 0d 73 68 | a mixtu|re of.sh|
|00000cf0| 65 6c 6c 20 73 63 72 69 | 70 74 73 2c 20 6d 61 6e |ell scri|pts, man|
|00000d00| 75 61 6c 6c 79 20 67 69 | 76 65 6e 20 73 68 65 6c |ually gi|ven shel|
|00000d10| 6c 20 63 6f 6d 6d 61 6e | 64 73 2c 20 61 6e 64 20 |l comman|ds, and |
|00000d20| 61 6e 20 6f 63 63 61 73 | 69 6f 6e 61 6c 20 61 64 |an occas|ional ad|
|00000d30| 20 68 6f 63 0d 43 20 70 | 72 6f 67 72 61 6d 2c 20 | hoc.C p|rogram, |
|00000d40| 50 79 74 68 6f 6e 20 68 | 61 73 20 65 76 6f 6c 76 |Python h|as evolv|
|00000d50| 65 64 20 69 6e 74 6f 20 | 61 20 67 65 6e 65 72 61 |ed into |a genera|
|00000d60| 6c 20 69 6e 74 65 72 61 | 63 74 69 76 65 20 70 72 |l intera|ctive pr|
|00000d70| 6f 74 6f 74 79 70 69 6e | 67 0d 6c 61 6e 67 75 61 |ototypin|g.langua|
|00000d80| 67 65 2e 20 20 49 74 20 | 68 61 73 20 62 65 65 6e |ge. It |has been|
|00000d90| 20 61 70 70 6c 69 65 64 | 20 74 6f 20 61 20 77 69 | applied| to a wi|
|00000da0| 64 65 20 72 61 6e 67 65 | 20 6f 66 20 70 72 6f 62 |de range| of prob|
|00000db0| 6c 65 6d 73 2c 20 66 72 | 6f 6d 0d 72 65 70 6c 61 |lems, fr|om.repla|
|00000dc0| 63 65 6d 65 6e 74 73 20 | 66 6f 72 20 6c 61 72 67 |cements |for larg|
|00000dd0| 65 20 73 68 65 6c 6c 20 | 73 63 72 69 70 74 73 20 |e shell |scripts |
|00000de0| 74 6f 20 66 61 6e 63 79 | 20 67 72 61 70 68 69 63 |to fancy| graphic|
|00000df0| 73 20 64 65 6d 6f 73 20 | 61 6e 64 0d 6d 75 6c 74 |s demos |and.mult|
|00000e00| 69 6d 65 64 69 61 20 61 | 70 70 6c 69 63 61 74 69 |imedia a|pplicati|
|00000e10| 6f 6e 73 2e 0d 0d 4f 6e | 65 20 6f 66 20 50 79 74 |ons...On|e of Pyt|
|00000e20| 68 6f 6e 27 73 20 73 74 | 72 65 6e 67 74 68 73 20 |hon's st|rengths |
|00000e30| 69 73 20 74 68 65 20 61 | 62 69 6c 69 74 79 20 66 |is the a|bility f|
|00000e40| 6f 72 20 74 68 65 20 75 | 73 65 72 20 74 6f 20 74 |or the u|ser to t|
|00000e50| 79 70 65 20 69 6e 20 73 | 6f 6d 65 0d 63 6f 64 65 |ype in s|ome.code|
|00000e60| 20 61 6e 64 20 69 6d 6d | 65 64 69 61 74 65 6c 79 | and imm|ediately|
|00000e70| 20 72 75 6e 20 69 74 3a | 20 6e 6f 20 63 6f 6d 70 | run it:| no comp|
|00000e80| 69 6c 61 74 69 6f 6e 20 | 6f 72 20 6c 69 6e 6b 69 |ilation |or linki|
|00000e90| 6e 67 20 69 73 20 6e 65 | 63 65 73 73 61 72 79 2e |ng is ne|cessary.|
|00000ea0| 0d 49 6e 74 65 72 61 63 | 74 69 76 65 20 70 65 72 |.Interac|tive per|
|00000eb0| 66 6f 72 6d 61 6e 63 65 | 20 69 73 20 66 75 72 74 |formance| is furt|
|00000ec0| 68 65 72 20 65 6e 68 61 | 6e 63 65 64 20 62 79 20 |her enha|nced by |
|00000ed0| 50 79 74 68 6f 6e 27 73 | 20 63 6f 6e 63 69 73 65 |Python's| concise|
|00000ee0| 2c 20 63 6c 65 61 72 0d | 73 79 6e 74 61 78 2c 20 |, clear.|syntax, |
|00000ef0| 69 74 73 20 76 65 72 79 | 2d 68 69 67 68 2d 6c 65 |its very|-high-le|
|00000f00| 76 65 6c 20 64 61 74 61 | 20 74 79 70 65 73 2c 20 |vel data| types, |
|00000f10| 61 6e 64 20 69 74 73 20 | 6c 61 63 6b 20 6f 66 20 |and its |lack of |
|00000f20| 64 65 63 6c 61 72 61 74 | 69 6f 6e 73 0d 28 77 68 |declarat|ions.(wh|
|00000f30| 69 63 68 20 69 73 20 63 | 6f 6d 70 65 6e 73 61 74 |ich is c|ompensat|
|00000f40| 65 64 20 62 79 20 72 75 | 6e 2d 74 69 6d 65 20 74 |ed by ru|n-time t|
|00000f50| 79 70 65 20 63 68 65 63 | 6b 69 6e 67 29 2e 20 20 |ype chec|king). |
|00000f60| 41 6c 6c 20 74 68 69 73 | 20 6d 61 6b 65 73 0d 70 |All this| makes.p|
|00000f70| 72 6f 67 72 61 6d 6d 69 | 6e 67 20 69 6e 20 50 79 |rogrammi|ng in Py|
|00000f80| 74 68 6f 6e 20 66 65 65 | 6c 20 6c 69 6b 65 20 61 |thon fee|l like a|
|00000f90| 20 6c 65 69 73 75 72 65 | 20 74 72 69 70 20 63 6f | leisure| trip co|
|00000fa0| 6d 70 61 72 65 64 20 74 | 6f 20 74 68 65 20 68 61 |mpared t|o the ha|
|00000fb0| 72 64 0d 77 6f 72 6b 20 | 69 6e 76 6f 6c 76 65 64 |rd.work |involved|
|00000fc0| 20 69 6e 20 77 72 69 74 | 69 6e 67 20 61 6e 64 20 | in writ|ing and |
|00000fd0| 64 65 62 75 67 67 69 6e | 67 20 65 76 65 6e 20 61 |debuggin|g even a|
|00000fe0| 20 73 6d 61 6c 6c 69 73 | 68 20 43 20 70 72 6f 67 | smallis|h C prog|
|00000ff0| 72 61 6d 2e 0d 0d 49 74 | 20 73 68 6f 75 6c 64 20 |ram...It| should |
|00001000| 62 65 20 63 6c 65 61 72 | 20 62 79 20 6e 6f 77 20 |be clear| by now |
|00001010| 74 68 61 74 20 50 79 74 | 68 6f 6e 20 77 69 6c 6c |that Pyt|hon will|
|00001020| 20 62 65 20 74 68 65 20 | 69 64 65 61 6c 20 74 6f | be the |ideal to|
|00001030| 6f 6c 20 74 6f 20 74 65 | 73 74 0d 73 65 72 76 65 |ol to te|st.serve|
|00001040| 72 73 20 61 6e 64 20 74 | 68 65 69 72 20 69 6e 74 |rs and t|heir int|
|00001050| 65 72 66 61 63 65 73 2e | 20 20 45 73 70 65 63 69 |erfaces.| Especi|
|00001060| 61 6c 6c 79 20 64 75 72 | 69 6e 67 20 74 68 65 20 |ally dur|ing the |
|00001070| 64 65 76 65 6c 6f 70 6d | 65 6e 74 20 6f 66 20 61 |developm|ent of a|
|00001080| 0d 63 6f 6d 70 6c 65 78 | 20 73 65 72 76 65 72 2c |.complex| server,|
|00001090| 20 6f 6e 65 20 6f 66 74 | 65 6e 20 6e 65 65 64 73 | one oft|en needs|
|000010a0| 20 74 6f 20 67 65 6e 65 | 72 61 74 65 20 74 65 73 | to gene|rate tes|
|000010b0| 74 20 72 65 71 75 65 73 | 74 73 20 6f 6e 20 61 6e |t reques|ts on an|
|000010c0| 20 61 64 20 68 6f 63 0d | 62 61 73 69 73 2c 20 74 | ad hoc.|basis, t|
|000010d0| 6f 20 61 6e 73 77 65 72 | 20 71 75 65 73 74 69 6f |o answer| questio|
|000010e0| 6e 73 20 6c 69 6b 65 20 | 60 60 77 68 61 74 20 68 |ns like |``what h|
|000010f0| 61 70 70 65 6e 73 20 69 | 66 20 72 65 71 75 65 73 |appens i|f reques|
|00001100| 74 20 58 20 61 72 72 69 | 76 65 73 0d 77 68 65 6e |t X arri|ves.when|
|00001110| 20 74 68 65 20 73 65 72 | 76 65 72 20 69 73 20 69 | the ser|ver is i|
|00001120| 6e 20 73 74 61 74 65 20 | 59 2c 27 27 20 74 6f 20 |n state |Y,'' to |
|00001130| 74 65 73 74 20 74 68 65 | 20 62 65 68 61 76 69 6f |test the| behavio|
|00001140| 72 20 6f 66 20 74 68 65 | 20 73 65 72 76 65 72 0d |r of the| server.|
|00001150| 77 69 74 68 20 72 65 71 | 75 65 73 74 73 20 74 68 |with req|uests th|
|00001160| 61 74 20 74 6f 75 63 68 | 20 69 74 73 20 6c 69 6d |at touch| its lim|
|00001170| 69 74 61 74 69 6f 6e 73 | 2c 20 74 6f 20 63 68 65 |itations|, to che|
|00001180| 63 6b 20 73 65 72 76 65 | 72 20 72 65 73 70 6f 6e |ck serve|r respon|
|00001190| 73 65 73 20 74 6f 0d 61 | 6c 6c 20 73 6f 72 74 73 |ses to.a|ll sorts|
|000011a0| 20 6f 66 20 77 72 6f 6e | 67 20 72 65 71 75 65 73 | of wron|g reques|
|000011b0| 74 73 2c 20 65 74 63 2e | 20 20 50 79 74 68 6f 6e |ts, etc.| Python|
|000011c0| 27 73 20 61 62 69 6c 69 | 74 79 20 74 6f 20 69 6d |'s abili|ty to im|
|000011d0| 6d 65 64 69 61 74 65 6c | 79 0d 65 78 65 63 75 74 |mediatel|y.execut|
|000011e0| 65 20 60 69 6d 70 72 6f | 76 69 73 65 64 27 20 63 |e `impro|vised' c|
|000011f0| 6f 64 65 20 6d 61 6b 65 | 73 20 69 74 20 61 20 6d |ode make|s it a m|
|00001200| 75 63 68 20 62 65 74 74 | 65 72 20 74 6f 6f 6c 20 |uch bett|er tool |
|00001210| 66 6f 72 20 74 68 69 73 | 0d 73 69 74 75 61 74 69 |for this|.situati|
|00001220| 6f 6e 20 74 68 61 6e 20 | 43 2e 0d 0d 54 68 65 20 |on than |C...The |
|00001230| 6c 69 6e 6b 20 74 6f 20 | 41 49 4c 20 65 78 74 65 |link to |AIL exte|
|00001240| 6e 64 73 20 50 79 74 68 | 6f 6e 20 77 69 74 68 20 |nds Pyth|on with |
|00001250| 74 68 65 20 6e 65 63 65 | 73 73 61 72 79 20 66 75 |the nece|ssary fu|
|00001260| 6e 63 74 69 6f 6e 61 6c | 69 74 79 20 74 6f 0d 63 |nctional|ity to.c|
|00001270| 6f 6e 6e 65 63 74 20 74 | 6f 20 61 72 62 69 74 72 |onnect t|o arbitr|
|00001280| 61 72 79 20 73 65 72 76 | 65 72 73 2c 20 6d 61 6b |ary serv|ers, mak|
|00001290| 69 6e 67 20 74 68 65 20 | 73 65 72 76 65 72 20 74 |ing the |server t|
|000012a0| 65 73 74 62 65 64 20 73 | 6b 65 74 63 68 65 64 20 |estbed s|ketched |
|000012b0| 61 62 6f 76 65 0d 61 20 | 72 65 61 6c 69 74 79 2e |above.a |reality.|
|000012c0| 20 20 50 79 74 68 6f 6e | 27 73 20 68 69 67 68 2d | Python|'s high-|
|000012d0| 6c 65 76 65 6c 20 64 61 | 74 61 20 74 79 70 65 73 |level da|ta types|
|000012e0| 2c 20 67 65 6e 65 72 61 | 6c 20 70 72 6f 67 72 61 |, genera|l progra|
|000012f0| 6d 6d 69 6e 67 0d 66 65 | 61 74 75 72 65 73 2c 20 |mming.fe|atures, |
|00001300| 61 6e 64 20 73 79 73 74 | 65 6d 20 69 6e 74 65 72 |and syst|em inter|
|00001310| 66 61 63 65 20 65 6e 73 | 75 72 65 20 74 68 61 74 |face ens|ure that|
|00001320| 20 69 74 20 68 61 73 20 | 61 6c 6c 20 74 68 65 20 | it has |all the |
|00001330| 70 6f 77 65 72 20 61 6e | 64 0d 66 6c 65 78 69 62 |power an|d.flexib|
|00001340| 69 6c 69 74 79 20 6e 65 | 65 64 65 64 20 66 6f 72 |ility ne|eded for|
|00001350| 20 74 68 65 20 6a 6f 62 | 2e 0d 0d 4f 6e 65 20 63 | the job|...One c|
|00001360| 6f 75 6c 64 20 67 6f 20 | 65 76 65 6e 20 66 75 72 |ould go |even fur|
|00001370| 74 68 65 72 20 74 68 61 | 6e 20 74 68 69 73 2e 20 |ther tha|n this. |
|00001380| 20 43 75 72 72 65 6e 74 | 20 64 69 73 74 72 69 62 | Current| distrib|
|00001390| 75 74 65 64 20 6f 70 65 | 72 61 74 69 6e 67 0d 73 |uted ope|rating.s|
|000013a0| 79 73 74 65 6d 73 2c 20 | 62 61 73 65 64 20 6f 6e |ystems, |based on|
|000013b0| 20 63 6c 69 65 6e 74 2d | 73 65 72 76 65 72 20 69 | client-|server i|
|000013c0| 6e 74 65 72 61 63 74 69 | 6f 6e 2c 20 61 6c 6c 20 |nteracti|on, all |
|000013d0| 6c 61 63 6b 20 61 20 67 | 6f 6f 64 20 63 6f 6d 6d |lack a g|ood comm|
|000013e0| 61 6e 64 0d 6c 61 6e 67 | 75 61 67 65 20 6f 72 20 |and.lang|uage or |
|000013f0| 60 73 68 65 6c 6c 27 20 | 74 6f 20 67 69 76 65 20 |`shell' |to give |
|00001400| 61 64 65 71 75 61 74 65 | 20 61 63 63 65 73 73 20 |adequate| access |
|00001410| 74 6f 20 61 76 61 69 6c | 61 62 6c 65 20 73 65 72 |to avail|able ser|
|00001420| 76 69 63 65 73 2e 0d 50 | 79 74 68 6f 6e 20 68 61 |vices..P|ython ha|
|00001430| 73 20 63 6f 6e 73 69 64 | 65 72 61 62 6c 65 20 70 |s consid|erable p|
|00001440| 6f 74 65 6e 74 69 61 6c | 20 66 6f 72 20 62 65 63 |otential| for bec|
|00001450| 6f 6d 69 6e 67 20 73 75 | 63 68 20 61 20 73 68 65 |oming su|ch a she|
|00001460| 6c 6c 2e 0d 0d 5c 73 75 | 62 73 65 63 74 69 6f 6e |ll...\su|bsection|
|00001470| 7b 4f 76 65 72 76 69 65 | 77 20 6f 66 20 74 68 69 |{Overvie|w of thi|
|00001480| 73 20 50 61 70 65 72 7d | 0d 0d 54 68 65 20 72 65 |s Paper}|..The re|
|00001490| 73 74 20 6f 66 20 74 68 | 69 73 20 70 61 70 65 72 |st of th|is paper|
|000014a0| 20 63 6f 6e 74 61 69 6e | 73 20 74 68 72 65 65 20 | contain|s three |
|000014b0| 6d 61 6a 6f 72 20 73 65 | 63 74 69 6f 6e 73 20 61 |major se|ctions a|
|000014c0| 6e 64 20 61 20 63 6f 6e | 63 6c 75 73 69 6f 6e 2e |nd a con|clusion.|
|000014d0| 0d 46 69 72 73 74 20 61 | 6e 20 6f 76 65 72 76 69 |.First a|n overvi|
|000014e0| 65 77 20 6f 66 20 74 68 | 65 20 50 79 74 68 6f 6e |ew of th|e Python|
|000014f0| 20 70 72 6f 67 72 61 6d | 6d 69 6e 67 20 6c 61 6e | program|ming lan|
|00001500| 67 75 61 67 65 20 69 73 | 20 67 69 76 65 6e 2e 20 |guage is| given. |
|00001510| 20 4e 65 78 74 0d 63 6f | 6d 65 73 20 61 20 73 68 | Next.co|mes a sh|
|00001520| 6f 72 74 20 64 65 73 63 | 72 69 70 74 69 6f 6e 20 |ort desc|ription |
|00001530| 6f 66 20 41 49 4c 2c 20 | 74 6f 67 65 74 68 65 72 |of AIL, |together|
|00001540| 20 77 69 74 68 20 73 6f | 6d 65 20 72 65 6c 65 76 | with so|me relev|
|00001550| 61 6e 74 20 64 65 74 61 | 69 6c 73 0d 61 62 6f 75 |ant deta|ils.abou|
|00001560| 74 20 41 6d 6f 65 62 61 | 2e 20 20 46 69 6e 61 6c |t Amoeba|. Final|
|00001570| 6c 79 2c 20 74 68 65 20 | 64 65 73 69 67 6e 20 61 |ly, the |design a|
|00001580| 6e 64 20 63 6f 6e 73 74 | 72 75 63 74 69 6f 6e 20 |nd const|ruction |
|00001590| 6f 66 20 74 68 65 20 6c | 69 6e 6b 0d 62 65 74 77 |of the l|ink.betw|
|000015a0| 65 65 6e 20 50 79 74 68 | 6f 6e 20 61 6e 64 20 41 |een Pyth|on and A|
|000015b0| 49 4c 20 69 73 20 64 65 | 73 63 72 69 62 65 64 20 |IL is de|scribed |
|000015c0| 69 6e 20 6d 75 63 68 20 | 64 65 74 61 69 6c 2e 20 |in much |detail. |
|000015d0| 20 54 68 65 20 63 6f 6e | 63 6c 75 73 69 6f 6e 0d | The con|clusion.|
|000015e0| 6c 6f 6f 6b 73 20 62 61 | 63 6b 20 61 74 20 74 68 |looks ba|ck at th|
|000015f0| 65 20 77 6f 72 6b 20 61 | 6e 64 20 70 6f 69 6e 74 |e work a|nd point|
|00001600| 73 20 6f 75 74 20 77 65 | 61 6b 6e 65 73 73 65 73 |s out we|aknesses|
|00001610| 20 61 6e 64 20 73 74 72 | 65 6e 67 74 68 73 20 6f | and str|engths o|
|00001620| 66 0d 50 79 74 68 6f 6e | 20 61 6e 64 20 41 49 4c |f.Python| and AIL|
|00001630| 20 74 68 61 74 20 77 65 | 72 65 20 64 69 73 63 6f | that we|re disco|
|00001640| 76 65 72 65 64 20 69 6e | 20 74 68 65 20 70 72 6f |vered in| the pro|
|00001650| 63 65 73 73 2e 0d 0d 5c | 73 65 63 74 69 6f 6e 7b |cess...\|section{|
|00001660| 41 6e 20 4f 76 65 72 76 | 69 65 77 20 6f 66 20 50 |An Overv|iew of P|
|00001670| 79 74 68 6f 6e 7d 0d 0d | 50 79 74 68 6f 6e 25 0d |ython}..|Python%.|
|00001680| 5c 66 6f 6f 74 6e 6f 74 | 65 7b 0d 4e 61 6d 65 64 |\footnot|e{.Named|
|00001690| 20 61 66 74 65 72 20 74 | 68 65 20 66 75 6e 6e 79 | after t|he funny|
|000016a0| 20 54 56 20 73 68 6f 77 | 2c 20 6e 6f 74 20 74 68 | TV show|, not th|
|000016b0| 65 20 6e 61 73 74 79 20 | 72 65 70 74 69 6c 65 2e |e nasty |reptile.|
|000016c0| 0d 7d 0d 6f 77 65 73 20 | 6d 75 63 68 20 74 6f 20 |.}.owes |much to |
|000016d0| 41 42 43 0d 5c 63 69 74 | 65 7b 41 42 43 7d 2c 0d |ABC.\cit|e{ABC},.|
|000016e0| 61 20 6c 61 6e 67 75 61 | 67 65 20 64 65 76 65 6c |a langua|ge devel|
|000016f0| 6f 70 65 64 20 61 74 20 | 43 57 49 20 61 73 20 61 |oped at |CWI as a|
|00001700| 20 70 72 6f 67 72 61 6d | 6d 69 6e 67 20 6c 61 6e | program|ming lan|
|00001710| 67 75 61 67 65 20 66 6f | 72 20 6e 6f 6e 2d 65 78 |guage fo|r non-ex|
|00001720| 70 65 72 74 0d 63 6f 6d | 70 75 74 65 72 20 75 73 |pert.com|puter us|
|00001730| 65 72 73 2e 20 20 50 79 | 74 68 6f 6e 20 62 6f 72 |ers. Py|thon bor|
|00001740| 72 6f 77 73 20 66 72 65 | 65 6c 79 20 66 72 6f 6d |rows fre|ely from|
|00001750| 20 41 42 43 27 73 20 73 | 79 6e 74 61 78 20 61 6e | ABC's s|yntax an|
|00001760| 64 20 64 61 74 61 0d 74 | 79 70 65 73 2c 20 62 75 |d data.t|ypes, bu|
|00001770| 74 20 61 64 64 73 20 6d | 6f 64 75 6c 65 73 2c 20 |t adds m|odules, |
|00001780| 65 78 63 65 70 74 69 6f | 6e 73 20 61 6e 64 20 63 |exceptio|ns and c|
|00001790| 6c 61 73 73 65 73 2c 20 | 65 78 74 65 6e 73 69 62 |lasses, |extensib|
|000017a0| 69 6c 69 74 79 2c 20 61 | 6e 64 0d 74 68 65 20 61 |ility, a|nd.the a|
|000017b0| 62 69 6c 69 74 79 20 74 | 6f 20 63 61 6c 6c 20 73 |bility t|o call s|
|000017c0| 79 73 74 65 6d 20 66 75 | 6e 63 74 69 6f 6e 73 2e |ystem fu|nctions.|
|000017d0| 20 20 54 68 65 20 63 6f | 6e 63 65 70 74 73 20 6f | The co|ncepts o|
|000017e0| 66 20 6d 6f 64 75 6c 65 | 73 2c 0d 65 78 63 65 70 |f module|s,.excep|
|000017f0| 74 69 6f 6e 73 20 61 6e | 64 20 28 74 6f 20 73 6f |tions an|d (to so|
|00001800| 6d 65 20 65 78 74 65 6e | 74 29 20 63 6c 61 73 73 |me exten|t) class|
|00001810| 65 73 20 61 72 65 20 69 | 6e 66 6c 75 65 6e 63 65 |es are i|nfluence|
|00001820| 64 20 73 74 72 6f 6e 67 | 6c 79 20 62 79 0d 74 68 |d strong|ly by.th|
|00001830| 65 69 72 20 6f 63 63 75 | 72 72 65 6e 63 65 20 69 |eir occu|rrence i|
|00001840| 6e 20 4d 6f 64 75 6c 61 | 2d 33 0d 5c 63 69 74 65 |n Modula|-3.\cite|
|00001850| 7b 4d 6f 64 75 6c 61 2d | 33 7d 2e 0d 0d 41 6c 74 |{Modula-|3}...Alt|
|00001860| 68 6f 75 67 68 20 50 79 | 74 68 6f 6e 20 72 65 73 |hough Py|thon res|
|00001870| 65 6d 62 6c 65 73 20 41 | 42 43 20 69 6e 20 6d 61 |embles A|BC in ma|
|00001880| 6e 79 20 77 61 79 73 2c | 20 74 68 65 72 65 20 69 |ny ways,| there i|
|00001890| 73 20 61 20 61 20 63 6c | 65 61 72 0d 64 69 66 66 |s a a cl|ear.diff|
|000018a0| 65 72 65 6e 63 65 20 69 | 6e 20 61 70 70 6c 69 63 |erence i|n applic|
|000018b0| 61 74 69 6f 6e 20 64 6f | 6d 61 69 6e 2e 20 20 41 |ation do|main. A|
|000018c0| 42 43 20 69 73 20 69 6e | 74 65 6e 64 65 64 20 74 |BC is in|tended t|
|000018d0| 6f 20 62 65 20 74 68 65 | 20 6f 6e 6c 79 0d 70 72 |o be the| only.pr|
|000018e0| 6f 67 72 61 6d 6d 69 6e | 67 20 6c 61 6e 67 75 61 |ogrammin|g langua|
|000018f0| 67 65 20 66 6f 72 20 74 | 68 6f 73 65 20 77 68 6f |ge for t|hose who|
|00001900| 20 75 73 65 20 61 20 63 | 6f 6d 70 75 74 65 72 20 | use a c|omputer |
|00001910| 61 73 20 61 20 74 6f 6f | 6c 2c 20 62 75 74 0d 6f |as a too|l, but.o|
|00001920| 63 63 61 73 69 6f 6e 61 | 6c 6c 79 20 6e 65 65 64 |ccasiona|lly need|
|00001930| 20 74 6f 20 77 72 69 74 | 65 20 61 20 70 72 6f 67 | to writ|e a prog|
|00001940| 72 61 6d 2e 20 20 46 6f | 72 20 74 68 69 73 20 72 |ram. Fo|r this r|
|00001950| 65 61 73 6f 6e 2c 20 41 | 42 43 20 69 73 20 6e 6f |eason, A|BC is no|
|00001960| 74 0d 6a 75 73 74 20 61 | 20 70 72 6f 67 72 61 6d |t.just a| program|
|00001970| 6d 69 6e 67 20 6c 61 6e | 67 75 61 67 65 20 62 75 |ming lan|guage bu|
|00001980| 74 20 61 6c 73 6f 20 61 | 20 70 72 6f 67 72 61 6d |t also a| program|
|00001990| 6d 69 6e 67 20 65 6e 76 | 69 72 6f 6e 6d 65 6e 74 |ming env|ironment|
|000019a0| 2c 20 77 68 69 63 68 0d | 63 6f 6d 65 73 20 77 69 |, which.|comes wi|
|000019b0| 74 68 20 61 6e 20 69 6e | 74 65 67 72 61 74 65 64 |th an in|tegrated|
|000019c0| 20 73 79 6e 74 61 78 2d | 64 69 72 65 63 74 65 64 | syntax-|directed|
|000019d0| 20 65 64 69 74 6f 72 20 | 61 6e 64 20 73 6f 6d 65 | editor |and some|
|000019e0| 20 73 6f 75 72 63 65 0d | 6d 61 6e 69 70 75 6c 61 | source.|manipula|
|000019f0| 74 69 6f 6e 20 63 6f 6d | 6d 61 6e 64 73 2e 20 20 |tion com|mands. |
|00001a00| 50 79 74 68 6f 6e 2c 20 | 6f 6e 20 74 68 65 20 6f |Python, |on the o|
|00001a10| 74 68 65 72 20 68 61 6e | 64 2c 20 61 69 6d 73 20 |ther han|d, aims |
|00001a20| 74 6f 20 62 65 20 61 20 | 74 6f 6f 6c 0d 66 6f 72 |to be a |tool.for|
|00001a30| 20 70 72 6f 66 65 73 73 | 69 6f 6e 61 6c 20 28 73 | profess|ional (s|
|00001a40| 79 73 74 65 6d 29 20 70 | 72 6f 67 72 61 6d 6d 65 |ystem) p|rogramme|
|00001a50| 72 73 2c 20 66 6f 72 20 | 77 68 6f 6d 20 68 61 76 |rs, for |whom hav|
|00001a60| 69 6e 67 20 61 20 63 68 | 6f 69 63 65 20 6f 66 0d |ing a ch|oice of.|
|00001a70| 6c 61 6e 67 75 61 67 65 | 73 20 77 69 74 68 20 64 |language|s with d|
|00001a80| 69 66 66 65 72 65 6e 74 | 20 66 65 61 74 75 72 65 |ifferent| feature|
|00001a90| 20 73 65 74 73 20 6d 61 | 6b 65 73 20 69 74 20 70 | sets ma|kes it p|
|00001aa0| 6f 73 73 69 62 6c 65 20 | 74 6f 20 63 68 6f 6f 73 |ossible |to choos|
|00001ab0| 65 20 60 74 68 65 0d 72 | 69 67 68 74 20 74 6f 6f |e `the.r|ight too|
|00001ac0| 6c 20 66 6f 72 20 74 68 | 65 20 6a 6f 62 2e 27 20 |l for th|e job.' |
|00001ad0| 20 54 68 65 20 66 65 61 | 74 75 72 65 73 20 61 64 | The fea|tures ad|
|00001ae0| 64 65 64 20 74 6f 20 50 | 79 74 68 6f 6e 20 6d 61 |ded to P|ython ma|
|00001af0| 6b 65 20 69 74 20 6d 6f | 72 65 0d 75 73 65 66 75 |ke it mo|re.usefu|
|00001b00| 6c 20 74 68 61 6e 20 41 | 42 43 20 69 6e 20 61 6e |l than A|BC in an|
|00001b10| 20 65 6e 76 69 72 6f 6e | 6d 65 6e 74 20 77 68 65 | environ|ment whe|
|00001b20| 72 65 20 61 63 63 65 73 | 73 20 74 6f 20 73 79 73 |re acces|s to sys|
|00001b30| 74 65 6d 20 66 75 6e 63 | 74 69 6f 6e 73 0d 28 73 |tem func|tions.(s|
|00001b40| 75 63 68 20 61 73 20 66 | 69 6c 65 20 61 6e 64 20 |uch as f|ile and |
|00001b50| 64 69 72 65 63 74 6f 72 | 79 20 6d 61 6e 69 70 75 |director|y manipu|
|00001b60| 6c 61 74 69 6f 6e 73 29 | 20 61 72 65 20 63 6f 6d |lations)| are com|
|00001b70| 6d 6f 6e 2e 20 20 54 68 | 65 79 20 61 6c 73 6f 0d |mon. Th|ey also.|
|00001b80| 73 75 70 70 6f 72 74 20 | 74 68 65 20 62 75 69 6c |support |the buil|
|00001b90| 64 69 6e 67 20 6f 66 20 | 6c 61 72 67 65 72 20 73 |ding of |larger s|
|00001ba0| 79 73 74 65 6d 73 20 61 | 6e 64 20 6c 69 62 72 61 |ystems a|nd libra|
|00001bb0| 72 69 65 73 2e 20 20 54 | 68 65 20 50 79 74 68 6f |ries. T|he Pytho|
|00001bc0| 6e 0d 69 6d 70 6c 65 6d | 65 6e 74 61 74 69 6f 6e |n.implem|entation|
|00001bd0| 20 6f 66 66 65 72 73 20 | 6c 69 74 74 6c 65 20 69 | offers |little i|
|00001be0| 6e 20 74 68 65 20 77 61 | 79 20 6f 66 20 61 20 70 |n the wa|y of a p|
|00001bf0| 72 6f 67 72 61 6d 6d 69 | 6e 67 20 65 6e 76 69 72 |rogrammi|ng envir|
|00001c00| 6f 6e 6d 65 6e 74 2c 0d | 62 75 74 20 69 73 20 64 |onment,.|but is d|
|00001c10| 65 73 69 67 6e 65 64 20 | 74 6f 20 69 6e 74 65 67 |esigned |to integ|
|00001c20| 72 61 74 65 20 73 65 61 | 6d 6c 65 73 73 6c 79 20 |rate sea|mlessly |
|00001c30| 77 69 74 68 20 65 78 69 | 73 74 69 6e 67 20 70 72 |with exi|sting pr|
|00001c40| 6f 67 72 61 6d 6d 69 6e | 67 0d 65 6e 76 69 72 6f |ogrammin|g.enviro|
|00001c50| 6e 6d 65 6e 74 73 20 28 | 65 2e 67 2e 20 55 4e 49 |nments (|e.g. UNI|
|00001c60| 58 20 61 6e 64 20 45 6d | 61 63 73 29 2e 0d 0d 50 |X and Em|acs)...P|
|00001c70| 65 72 68 61 70 73 20 74 | 68 65 20 62 65 73 74 20 |erhaps t|he best |
|00001c80| 69 6e 74 72 6f 64 75 63 | 74 69 6f 6e 20 74 6f 20 |introduc|tion to |
|00001c90| 50 79 74 68 6f 6e 20 69 | 73 20 61 20 73 68 6f 72 |Python i|s a shor|
|00001ca0| 74 20 65 78 61 6d 70 6c | 65 2e 20 20 54 68 65 0d |t exampl|e. The.|
|00001cb0| 66 6f 6c 6c 6f 77 69 6e | 67 20 69 73 20 61 20 63 |followin|g is a c|
|00001cc0| 6f 6d 70 6c 65 74 65 20 | 50 79 74 68 6f 6e 20 70 |omplete |Python p|
|00001cd0| 72 6f 67 72 61 6d 20 74 | 6f 20 6c 69 73 74 20 74 |rogram t|o list t|
|00001ce0| 68 65 20 63 6f 6e 74 65 | 6e 74 73 20 6f 66 20 61 |he conte|nts of a|
|00001cf0| 20 55 4e 49 58 0d 64 69 | 72 65 63 74 6f 72 79 2e | UNIX.di|rectory.|
|00001d00| 0d 5c 62 65 67 69 6e 7b | 76 65 72 62 61 74 69 6d |.\begin{|verbatim|
|00001d10| 7d 0d 69 6d 70 6f 72 74 | 20 73 79 73 2c 20 70 6f |}.import| sys, po|
|00001d20| 73 69 78 0d 0d 64 65 66 | 20 6c 73 28 64 69 72 6e |six..def| ls(dirn|
|00001d30| 61 6d 65 29 3a 20 20 20 | 20 23 20 50 72 69 6e 74 |ame): | # Print|
|00001d40| 20 73 6f 72 74 65 64 20 | 64 69 72 65 63 74 6f 72 | sorted |director|
|00001d50| 79 20 63 6f 6e 74 65 6e | 74 73 0d 20 20 20 20 6e |y conten|ts. n|
|00001d60| 61 6d 65 73 20 3d 20 70 | 6f 73 69 78 2e 6c 69 73 |ames = p|osix.lis|
|00001d70| 74 64 69 72 28 64 69 72 | 6e 61 6d 65 29 0d 20 20 |tdir(dir|name). |
|00001d80| 20 20 6e 61 6d 65 73 2e | 73 6f 72 74 28 29 0d 20 | names.|sort(). |
|00001d90| 20 20 20 66 6f 72 20 6e | 61 6d 65 20 69 6e 20 6e | for n|ame in n|
|00001da0| 61 6d 65 73 3a 0d 20 20 | 20 20 20 20 20 20 69 66 |ames:. | if|
|00001db0| 20 6e 61 6d 65 5b 30 5d | 20 21 3d 20 27 2e 27 3a | name[0]| != '.':|
|00001dc0| 20 70 72 69 6e 74 20 6e | 61 6d 65 0d 0d 6c 73 28 | print n|ame..ls(|
|00001dd0| 73 79 73 2e 61 72 67 76 | 5b 31 5d 29 0d 5c 65 6e |sys.argv|[1]).\en|
|00001de0| 64 7b 76 65 72 62 61 74 | 69 6d 7d 0d 54 68 65 20 |d{verbat|im}.The |
|00001df0| 6c 61 72 67 65 73 74 20 | 70 61 72 74 20 6f 66 20 |largest |part of |
|00001e00| 74 68 69 73 20 70 72 6f | 67 72 61 6d 2c 20 69 6e |this pro|gram, in|
|00001e10| 20 74 68 65 20 6d 69 64 | 64 6c 65 20 73 74 61 72 | the mid|dle star|
|00001e20| 74 69 6e 67 20 77 69 74 | 68 20 7b 5c 74 74 0d 64 |ting wit|h {\tt.d|
|00001e30| 65 66 7d 2c 20 69 73 20 | 61 20 66 75 6e 63 74 69 |ef}, is |a functi|
|00001e40| 6f 6e 20 64 65 66 69 6e | 69 74 69 6f 6e 2e 20 20 |on defin|ition. |
|00001e50| 49 74 20 64 65 66 69 6e | 65 73 20 61 20 66 75 6e |It defin|es a fun|
|00001e60| 63 74 69 6f 6e 20 6e 61 | 6d 65 64 20 7b 5c 74 74 |ction na|med {\tt|
|00001e70| 20 6c 73 7d 0d 77 69 74 | 68 20 61 20 73 69 6e 67 | ls}.wit|h a sing|
|00001e80| 6c 65 20 70 61 72 61 6d | 65 74 65 72 20 63 61 6c |le param|eter cal|
|00001e90| 6c 65 64 20 7b 5c 74 74 | 20 64 69 72 6e 61 6d 65 |led {\tt| dirname|
|00001ea0| 7d 2e 20 20 28 43 6f 6d | 6d 65 6e 74 73 20 69 6e |}. (Com|ments in|
|00001eb0| 20 50 79 74 68 6f 6e 0d | 73 74 61 72 74 20 77 69 | Python.|start wi|
|00001ec0| 74 68 20 60 5c 23 27 20 | 61 6e 64 20 65 78 74 65 |th `\#' |and exte|
|00001ed0| 6e 64 20 74 6f 20 74 68 | 65 20 65 6e 64 20 6f 66 |nd to th|e end of|
|00001ee0| 20 74 68 65 20 6c 69 6e | 65 2e 29 20 20 54 68 65 | the lin|e.) The|
|00001ef0| 20 66 75 6e 63 74 69 6f | 6e 20 62 6f 64 79 0d 69 | functio|n body.i|
|00001f00| 73 20 69 6e 64 65 6e 74 | 65 64 3a 20 50 79 74 68 |s indent|ed: Pyth|
|00001f10| 6f 6e 20 75 73 65 73 20 | 69 6e 64 65 6e 74 61 74 |on uses |indentat|
|00001f20| 69 6f 6e 20 66 6f 72 20 | 73 74 61 74 65 6d 65 6e |ion for |statemen|
|00001f30| 74 20 67 72 6f 75 70 69 | 6e 67 20 69 6e 73 74 65 |t groupi|ng inste|
|00001f40| 61 64 20 6f 66 0d 62 72 | 61 63 65 73 20 6f 72 20 |ad of.br|aces or |
|00001f50| 62 65 67 69 6e 2f 65 6e | 64 20 6b 65 79 77 6f 72 |begin/en|d keywor|
|00001f60| 64 73 2e 20 20 54 68 69 | 73 20 69 73 20 73 68 6f |ds. Thi|s is sho|
|00001f70| 72 74 65 72 20 74 6f 20 | 74 79 70 65 20 61 6e 64 |rter to |type and|
|00001f80| 20 61 76 6f 69 64 73 0d | 66 72 75 73 74 72 61 74 | avoids.|frustrat|
|00001f90| 69 6e 67 20 6d 69 73 6d | 61 74 63 68 65 73 20 62 |ing mism|atches b|
|00001fa0| 65 74 77 65 65 6e 20 74 | 68 65 20 70 65 72 63 65 |etween t|he perce|
|00001fb0| 70 74 69 6f 6e 20 6f 66 | 20 67 72 6f 75 70 69 6e |ption of| groupin|
|00001fc0| 67 20 62 79 20 74 68 65 | 20 75 73 65 72 0d 61 6e |g by the| user.an|
|00001fd0| 64 20 74 68 65 20 70 61 | 72 73 65 72 2e 20 20 50 |d the pa|rser. P|
|00001fe0| 79 74 68 6f 6e 20 61 63 | 63 65 70 74 73 20 6f 6e |ython ac|cepts on|
|00001ff0| 65 20 73 74 61 74 65 6d | 65 6e 74 20 70 65 72 20 |e statem|ent per |
|00002000| 6c 69 6e 65 3b 20 6c 6f | 6e 67 0d 73 74 61 74 65 |line; lo|ng.state|
|00002010| 6d 65 6e 74 73 20 6d 61 | 79 20 62 65 20 62 72 6f |ments ma|y be bro|
|00002020| 6b 65 6e 20 69 6e 20 70 | 69 65 63 65 73 20 75 73 |ken in p|ieces us|
|00002030| 69 6e 67 20 74 68 65 20 | 73 74 61 6e 64 61 72 64 |ing the |standard|
|00002040| 20 62 61 63 6b 73 6c 61 | 73 68 0d 63 6f 6e 76 65 | backsla|sh.conve|
|00002050| 6e 74 69 6f 6e 2e 20 20 | 49 66 20 74 68 65 20 62 |ntion. |If the b|
|00002060| 6f 64 79 20 6f 66 20 61 | 20 63 6f 6d 70 6f 75 6e |ody of a| compoun|
|00002070| 64 20 73 74 61 74 65 6d | 65 6e 74 20 69 73 20 61 |d statem|ent is a|
|00002080| 20 73 69 6e 67 6c 65 2c | 20 73 69 6d 70 6c 65 0d | single,| simple.|
|00002090| 73 74 61 74 65 6d 65 6e | 74 2c 20 69 74 20 6d 61 |statemen|t, it ma|
|000020a0| 79 20 62 65 20 70 6c 61 | 63 65 64 20 6f 6e 20 74 |y be pla|ced on t|
|000020b0| 68 65 20 73 61 6d 65 20 | 6c 69 6e 65 20 61 73 20 |he same |line as |
|000020c0| 74 68 65 20 68 65 61 64 | 2e 0d 0d 54 68 65 20 66 |the head|...The f|
|000020d0| 69 72 73 74 20 73 74 61 | 74 65 6d 65 6e 74 20 6f |irst sta|tement o|
|000020e0| 66 20 74 68 65 20 66 75 | 6e 63 74 69 6f 6e 20 62 |f the fu|nction b|
|000020f0| 6f 64 79 20 63 61 6c 6c | 73 20 74 68 65 20 66 75 |ody call|s the fu|
|00002100| 6e 63 74 69 6f 6e 20 7b | 5c 74 74 0d 6c 69 73 74 |nction {|\tt.list|
|00002110| 64 69 72 7d 20 64 65 66 | 69 6e 65 64 20 69 6e 20 |dir} def|ined in |
|00002120| 74 68 65 20 6d 6f 64 75 | 6c 65 20 7b 5c 74 74 20 |the modu|le {\tt |
|00002130| 70 6f 73 69 78 7d 2e 20 | 20 54 68 69 73 20 66 75 |posix}. | This fu|
|00002140| 6e 63 74 69 6f 6e 20 72 | 65 74 75 72 6e 73 20 61 |nction r|eturns a|
|00002150| 0d 6c 69 73 74 20 6f 66 | 20 73 74 72 69 6e 67 73 |.list of| strings|
|00002160| 20 72 65 70 72 65 73 65 | 6e 74 69 6e 67 20 74 68 | represe|nting th|
|00002170| 65 20 63 6f 6e 74 65 6e | 74 73 20 6f 66 20 74 68 |e conten|ts of th|
|00002180| 65 20 64 69 72 65 63 74 | 6f 72 79 20 6e 61 6d 65 |e direct|ory name|
|00002190| 20 70 61 73 73 65 64 0d | 61 73 20 61 20 73 74 72 | passed.|as a str|
|000021a0| 69 6e 67 20 61 72 67 75 | 6d 65 6e 74 2c 20 68 65 |ing argu|ment, he|
|000021b0| 72 65 20 74 68 65 20 61 | 72 67 75 6d 65 6e 74 20 |re the a|rgument |
|000021c0| 7b 5c 74 74 20 64 69 72 | 6e 61 6d 65 7d 2e 20 20 |{\tt dir|name}. |
|000021d0| 49 66 20 7b 5c 74 74 0d | 64 69 72 6e 61 6d 65 7d |If {\tt.|dirname}|
|000021e0| 20 77 65 72 65 20 6e 6f | 74 20 61 20 76 61 6c 69 | were no|t a vali|
|000021f0| 64 20 64 69 72 65 63 74 | 6f 72 79 20 6e 61 6d 65 |d direct|ory name|
|00002200| 2c 20 6f 72 20 70 65 72 | 68 61 70 73 20 6e 6f 74 |, or per|haps not|
|00002210| 20 65 76 65 6e 20 61 0d | 73 74 72 69 6e 67 2c 20 | even a.|string, |
|00002220| 7b 5c 74 74 20 6c 69 73 | 74 64 69 72 7d 20 77 6f |{\tt lis|tdir} wo|
|00002230| 75 6c 64 20 72 61 69 73 | 65 20 61 6e 20 65 78 63 |uld rais|e an exc|
|00002240| 65 70 74 69 6f 6e 20 61 | 6e 64 20 74 68 65 20 6e |eption a|nd the n|
|00002250| 65 78 74 20 73 74 61 74 | 65 6d 65 6e 74 0d 77 6f |ext stat|ement.wo|
|00002260| 75 6c 64 20 6e 65 76 65 | 72 20 62 65 20 72 65 61 |uld neve|r be rea|
|00002270| 63 68 65 64 2e 20 20 28 | 45 78 63 65 70 74 69 6f |ched. (|Exceptio|
|00002280| 6e 73 20 63 61 6e 20 62 | 65 20 63 61 75 67 68 74 |ns can b|e caught|
|00002290| 20 69 6e 20 50 79 74 68 | 6f 6e 3b 20 73 65 65 0d | in Pyth|on; see.|
|000022a0| 6c 61 74 65 72 2e 29 20 | 20 41 73 73 75 6d 69 6e |later.) | Assumin|
|000022b0| 67 20 7b 5c 74 74 20 6c | 69 73 74 64 69 72 7d 20 |g {\tt l|istdir} |
|000022c0| 72 65 74 75 72 6e 73 20 | 6e 6f 72 6d 61 6c 6c 79 |returns |normally|
|000022d0| 2c 20 69 74 73 20 72 65 | 73 75 6c 74 20 69 73 0d |, its re|sult is.|
|000022e0| 61 73 73 69 67 6e 65 64 | 20 74 6f 20 74 68 65 20 |assigned| to the |
|000022f0| 6c 6f 63 61 6c 20 76 61 | 72 69 61 62 6c 65 20 7b |local va|riable {|
|00002300| 5c 74 74 20 6e 61 6d 65 | 73 7d 2e 0d 0d 54 68 65 |\tt name|s}...The|
|00002310| 20 73 65 63 6f 6e 64 20 | 73 74 61 74 65 6d 65 6e | second |statemen|
|00002320| 74 20 63 61 6c 6c 73 20 | 74 68 65 20 6d 65 74 68 |t calls |the meth|
|00002330| 6f 64 20 7b 5c 74 74 20 | 73 6f 72 74 7d 20 6f 66 |od {\tt |sort} of|
|00002340| 20 74 68 65 20 76 61 72 | 69 61 62 6c 65 20 7b 5c | the var|iable {\|
|00002350| 74 74 0d 6e 61 6d 65 73 | 7d 2e 20 20 54 68 69 73 |tt.names|}. This|
|00002360| 20 6d 65 74 68 6f 64 20 | 69 73 20 64 65 66 69 6e | method |is defin|
|00002370| 65 64 20 66 6f 72 20 61 | 6c 6c 20 6c 69 73 74 73 |ed for a|ll lists|
|00002380| 20 69 6e 20 50 79 74 68 | 6f 6e 20 61 6e 64 20 64 | in Pyth|on and d|
|00002390| 6f 65 73 20 74 68 65 0d | 6f 62 76 69 6f 75 73 20 |oes the.|obvious |
|000023a0| 74 68 69 6e 67 3a 20 74 | 68 65 20 65 6c 65 6d 65 |thing: t|he eleme|
|000023b0| 6e 74 73 20 6f 66 20 74 | 68 65 20 6c 69 73 74 20 |nts of t|he list |
|000023c0| 61 72 65 20 72 65 6f 72 | 64 65 72 65 64 20 61 63 |are reor|dered ac|
|000023d0| 63 6f 72 64 69 6e 67 20 | 74 6f 0d 74 68 65 69 72 |cording |to.their|
|000023e0| 20 6e 61 74 75 72 61 6c | 20 6f 72 64 65 72 69 6e | natural| orderin|
|000023f0| 67 20 72 65 6c 61 74 69 | 6f 6e 73 68 69 70 2e 20 |g relati|onship. |
|00002400| 20 53 69 6e 63 65 20 69 | 6e 20 6f 75 72 20 65 78 | Since i|n our ex|
|00002410| 61 6d 70 6c 65 20 74 68 | 65 20 6c 69 73 74 0d 63 |ample th|e list.c|
|00002420| 6f 6e 74 61 69 6e 73 20 | 73 74 72 69 6e 67 73 2c |ontains |strings,|
|00002430| 20 74 68 65 79 20 61 72 | 65 20 73 6f 72 74 65 64 | they ar|e sorted|
|00002440| 20 69 6e 20 61 73 63 65 | 6e 64 69 6e 67 20 41 53 | in asce|nding AS|
|00002450| 43 49 49 20 6f 72 64 65 | 72 2e 0d 0d 54 68 65 20 |CII orde|r...The |
|00002460| 6c 61 73 74 20 74 77 6f | 20 6c 69 6e 65 73 20 6f |last two| lines o|
|00002470| 66 20 74 68 65 20 66 75 | 6e 63 74 69 6f 6e 20 63 |f the fu|nction c|
|00002480| 6f 6e 74 61 69 6e 20 61 | 20 6c 6f 6f 70 20 74 68 |ontain a| loop th|
|00002490| 61 74 20 70 72 69 6e 74 | 73 20 61 6c 6c 0d 65 6c |at print|s all.el|
|000024a0| 65 6d 65 6e 74 73 20 6f | 66 20 74 68 65 20 6c 69 |ements o|f the li|
|000024b0| 73 74 20 77 68 6f 73 65 | 20 66 69 72 73 74 20 63 |st whose| first c|
|000024c0| 68 61 72 61 63 74 65 72 | 20 69 73 6e 27 74 20 61 |haracter| isn't a|
|000024d0| 20 70 65 72 69 6f 64 2e | 20 20 49 6e 20 65 61 63 | period.| In eac|
|000024e0| 68 0d 69 74 65 72 61 74 | 69 6f 6e 2c 20 74 68 65 |h.iterat|ion, the|
|000024f0| 20 7b 5c 74 74 20 66 6f | 72 7d 20 73 74 61 74 65 | {\tt fo|r} state|
|00002500| 6d 65 6e 74 20 61 73 73 | 69 67 6e 73 20 61 6e 20 |ment ass|igns an |
|00002510| 65 6c 65 6d 65 6e 74 20 | 6f 66 20 74 68 65 20 6c |element |of the l|
|00002520| 69 73 74 20 74 6f 0d 74 | 68 65 20 6c 6f 63 61 6c |ist to.t|he local|
|00002530| 20 76 61 72 69 61 62 6c | 65 20 7b 5c 74 74 20 6e | variabl|e {\tt n|
|00002540| 61 6d 65 7d 2e 20 20 54 | 68 65 20 7b 5c 74 74 20 |ame}. T|he {\tt |
|00002550| 70 72 69 6e 74 7d 20 73 | 74 61 74 65 6d 65 6e 74 |print} s|tatement|
|00002560| 20 69 73 20 69 6e 74 65 | 6e 64 65 64 0d 66 6f 72 | is inte|nded.for|
|00002570| 20 73 69 6d 70 6c 65 2d | 6d 69 6e 64 65 64 20 6f | simple-|minded o|
|00002580| 75 74 70 75 74 3b 20 6d | 6f 72 65 20 65 6c 61 62 |utput; m|ore elab|
|00002590| 6f 72 61 74 65 20 66 6f | 72 6d 61 74 74 69 6e 67 |orate fo|rmatting|
|000025a0| 20 69 73 20 70 6f 73 73 | 69 62 6c 65 20 77 69 74 | is poss|ible wit|
|000025b0| 68 0d 50 79 74 68 6f 6e | 27 73 20 73 74 72 69 6e |h.Python|'s strin|
|000025c0| 67 20 68 61 6e 64 6c 69 | 6e 67 20 66 75 6e 63 74 |g handli|ng funct|
|000025d0| 69 6f 6e 73 2e 0d 0d 54 | 68 65 20 6f 74 68 65 72 |ions...T|he other|
|000025e0| 20 74 77 6f 20 70 61 72 | 74 73 20 6f 66 20 74 68 | two par|ts of th|
|000025f0| 65 20 70 72 6f 67 72 61 | 6d 20 61 72 65 20 65 61 |e progra|m are ea|
|00002600| 73 69 6c 79 20 65 78 70 | 6c 61 69 6e 65 64 2e 20 |sily exp|lained. |
|00002610| 20 54 68 65 20 66 69 72 | 73 74 0d 6c 69 6e 65 20 | The fir|st.line |
|00002620| 69 73 20 61 6e 20 7b 5c | 74 74 20 69 6d 70 6f 72 |is an {\|tt impor|
|00002630| 74 7d 20 73 74 61 74 65 | 6d 65 6e 74 20 74 68 61 |t} state|ment tha|
|00002640| 74 20 74 65 6c 6c 73 20 | 74 68 65 20 69 6e 74 65 |t tells |the inte|
|00002650| 72 70 72 65 74 65 72 20 | 74 6f 20 69 6d 70 6f 72 |rpreter |to impor|
|00002660| 74 0d 74 68 65 20 6d 6f | 64 75 6c 65 73 20 7b 5c |t.the mo|dules {\|
|00002670| 74 74 20 73 79 73 7d 20 | 61 6e 64 20 7b 5c 74 74 |tt sys} |and {\tt|
|00002680| 20 70 6f 73 69 78 7d 2e | 20 20 41 73 20 69 74 20 | posix}.| As it |
|00002690| 68 61 70 70 65 6e 73 20 | 74 68 65 73 65 20 61 72 |happens |these ar|
|000026a0| 65 20 62 6f 74 68 0d 62 | 75 69 6c 74 20 69 6e 74 |e both.b|uilt int|
|000026b0| 6f 20 74 68 65 20 69 6e | 74 65 72 70 72 65 74 65 |o the in|terprete|
|000026c0| 72 2e 20 20 49 6d 70 6f | 72 74 69 6e 67 20 61 20 |r. Impo|rting a |
|000026d0| 6d 6f 64 75 6c 65 20 28 | 62 75 69 6c 74 2d 69 6e |module (|built-in|
|000026e0| 20 6f 72 0d 6f 74 68 65 | 72 77 69 73 65 29 20 6f | or.othe|rwise) o|
|000026f0| 6e 6c 79 20 6d 61 6b 65 | 73 20 74 68 65 20 6d 6f |nly make|s the mo|
|00002700| 64 75 6c 65 20 6e 61 6d | 65 20 61 76 61 69 6c 61 |dule nam|e availa|
|00002710| 62 6c 65 20 69 6e 20 74 | 68 65 20 63 75 72 72 65 |ble in t|he curre|
|00002720| 6e 74 20 73 63 6f 70 65 | 3b 0d 66 75 6e 63 74 69 |nt scope|;.functi|
|00002730| 6f 6e 73 20 61 6e 64 20 | 64 61 74 61 20 64 65 66 |ons and |data def|
|00002740| 69 6e 65 64 20 69 6e 20 | 74 68 65 20 6d 6f 64 75 |ined in |the modu|
|00002750| 6c 65 20 61 72 65 20 61 | 63 63 65 73 73 65 64 20 |le are a|ccessed |
|00002760| 74 68 72 6f 75 67 68 20 | 74 68 65 20 64 6f 74 0d |through |the dot.|
|00002770| 6e 6f 74 61 74 69 6f 6e | 20 61 73 20 69 6e 20 7b |notation| as in {|
|00002780| 5c 74 74 20 70 6f 73 69 | 78 2e 6c 69 73 74 64 69 |\tt posi|x.listdi|
|00002790| 72 7d 2e 20 20 54 68 65 | 20 73 63 6f 70 65 20 72 |r}. The| scope r|
|000027a0| 75 6c 65 73 20 6f 66 20 | 50 79 74 68 6f 6e 20 61 |ules of |Python a|
|000027b0| 72 65 0d 73 75 63 68 20 | 74 68 61 74 20 74 68 65 |re.such |that the|
|000027c0| 20 69 6d 70 6f 72 74 65 | 64 20 6d 6f 64 75 6c 65 | importe|d module|
|000027d0| 20 6e 61 6d 65 20 7b 5c | 74 74 20 70 6f 73 69 78 | name {\|tt posix|
|000027e0| 7d 20 69 73 20 61 6c 73 | 6f 20 61 76 61 69 6c 61 |} is als|o availa|
|000027f0| 62 6c 65 20 69 6e 0d 74 | 68 65 20 66 75 6e 63 74 |ble in.t|he funct|
|00002800| 69 6f 6e 20 7b 5c 74 74 | 20 6c 73 7d 20 28 74 68 |ion {\tt| ls} (th|
|00002810| 69 73 20 77 69 6c 6c 20 | 62 65 20 64 69 73 63 75 |is will |be discu|
|00002820| 73 73 65 64 20 69 6e 20 | 6d 6f 72 65 20 64 65 74 |ssed in |more det|
|00002830| 61 69 6c 20 6c 61 74 65 | 72 29 2e 0d 0d 46 69 6e |ail late|r)...Fin|
|00002840| 61 6c 6c 79 2c 20 74 68 | 65 20 6c 61 73 74 20 6c |ally, th|e last l|
|00002850| 69 6e 65 20 6f 66 20 74 | 68 65 20 70 72 6f 67 72 |ine of t|he progr|
|00002860| 61 6d 20 63 61 6c 6c 73 | 20 74 68 65 20 7b 5c 74 |am calls| the {\t|
|00002870| 74 20 6c 73 7d 20 66 75 | 6e 63 74 69 6f 6e 20 77 |t ls} fu|nction w|
|00002880| 69 74 68 0d 61 20 64 65 | 66 69 6e 69 74 65 20 61 |ith.a de|finite a|
|00002890| 72 67 75 6d 65 6e 74 2e | 20 20 49 74 20 6d 75 73 |rgument.| It mus|
|000028a0| 74 20 62 65 20 6c 61 73 | 74 20 73 69 6e 63 65 20 |t be las|t since |
|000028b0| 50 79 74 68 6f 6e 20 6f | 62 6a 65 63 74 73 20 6d |Python o|bjects m|
|000028c0| 75 73 74 20 62 65 0d 64 | 65 66 69 6e 65 64 20 62 |ust be.d|efined b|
|000028d0| 65 66 6f 72 65 20 74 68 | 65 79 20 63 61 6e 20 62 |efore th|ey can b|
|000028e0| 65 20 75 73 65 64 3b 20 | 69 6e 20 70 61 72 74 69 |e used; |in parti|
|000028f0| 63 75 6c 61 72 2c 20 74 | 68 65 20 66 75 6e 63 74 |cular, t|he funct|
|00002900| 69 6f 6e 20 7b 5c 74 74 | 20 6c 73 7d 0d 6d 75 73 |ion {\tt| ls}.mus|
|00002910| 74 20 62 65 20 64 65 66 | 69 6e 65 64 20 62 65 66 |t be def|ined bef|
|00002920| 6f 72 65 20 69 74 20 63 | 61 6e 20 62 65 20 63 61 |ore it c|an be ca|
|00002930| 6c 6c 65 64 2e 20 20 54 | 68 65 20 61 72 67 75 6d |lled. T|he argum|
|00002940| 65 6e 74 20 74 6f 20 7b | 5c 74 74 20 6c 73 7d 20 |ent to {|\tt ls} |
|00002950| 69 73 0d 7b 5c 74 74 20 | 73 79 73 2e 61 72 67 76 |is.{\tt |sys.argv|
|00002960| 5b 31 5d 7d 2c 20 77 68 | 69 63 68 20 68 61 70 70 |[1]}, wh|ich happ|
|00002970| 65 6e 73 20 74 6f 20 62 | 65 20 74 68 65 20 50 79 |ens to b|e the Py|
|00002980| 74 68 6f 6e 20 65 71 75 | 69 76 61 6c 65 6e 74 20 |thon equ|ivalent |
|00002990| 6f 66 20 7b 5c 74 74 0d | 5c 24 31 7d 20 69 6e 20 |of {\tt.|\$1} in |
|000029a0| 61 20 73 68 65 6c 6c 20 | 73 63 72 69 70 74 20 6f |a shell |script o|
|000029b0| 72 20 7b 5c 74 74 20 61 | 72 67 76 5b 31 5d 7d 20 |r {\tt a|rgv[1]} |
|000029c0| 69 6e 20 61 20 43 20 70 | 72 6f 67 72 61 6d 27 73 |in a C p|rogram's|
|000029d0| 20 7b 5c 74 74 20 6d 61 | 69 6e 7d 0d 66 75 6e 63 | {\tt ma|in}.func|
|000029e0| 74 69 6f 6e 2e 0d 0d 5c | 73 75 62 73 65 63 74 69 |tion...\|subsecti|
|000029f0| 6f 6e 7b 50 79 74 68 6f | 6e 20 44 61 74 61 20 54 |on{Pytho|n Data T|
|00002a00| 79 70 65 73 7d 0d 0d 28 | 54 68 69 73 20 61 6e 64 |ypes}..(|This and|
|00002a10| 20 74 68 65 20 66 6f 6c | 6c 6f 77 69 6e 67 20 73 | the fol|lowing s|
|00002a20| 75 62 73 65 63 74 69 6f | 6e 73 20 64 65 73 63 72 |ubsectio|ns descr|
|00002a30| 69 62 65 20 50 79 74 68 | 6f 6e 20 69 6e 20 71 75 |ibe Pyth|on in qu|
|00002a40| 69 74 65 20 61 20 6c 6f | 74 20 6f 66 0d 64 65 74 |ite a lo|t of.det|
|00002a50| 61 69 6c 2e 20 20 49 66 | 20 79 6f 75 20 61 72 65 |ail. If| you are|
|00002a60| 20 6d 6f 72 65 20 69 6e | 74 65 72 65 73 74 65 64 | more in|terested|
|00002a70| 20 69 6e 20 41 49 4c 2c | 20 41 6d 6f 65 62 61 20 | in AIL,| Amoeba |
|00002a80| 61 6e 64 20 68 6f 77 20 | 74 68 65 79 20 61 72 65 |and how |they are|
|00002a90| 0d 6c 69 6e 6b 65 64 20 | 77 69 74 68 20 50 79 74 |.linked |with Pyt|
|00002aa0| 68 6f 6e 2c 20 79 6f 75 | 20 63 61 6e 20 73 6b 69 |hon, you| can ski|
|00002ab0| 70 20 74 6f 20 73 65 63 | 74 69 6f 6e 20 33 20 6e |p to sec|tion 3 n|
|00002ac0| 6f 77 2e 29 0d 0d 50 79 | 74 68 6f 6e 27 73 20 73 |ow.)..Py|thon's s|
|00002ad0| 79 6e 74 61 78 20 6d 61 | 79 20 6e 6f 74 20 68 61 |yntax ma|y not ha|
|00002ae0| 76 65 20 62 69 67 20 73 | 75 72 70 72 69 73 65 73 |ve big s|urprises|
|00002af0| 20 28 77 68 69 63 68 20 | 69 73 20 65 78 61 63 74 | (which |is exact|
|00002b00| 6c 79 20 61 73 20 69 74 | 0d 73 68 6f 75 6c 64 20 |ly as it|.should |
|00002b10| 62 65 29 2c 20 62 75 74 | 20 69 74 73 20 64 61 74 |be), but| its dat|
|00002b20| 61 20 74 79 70 65 73 20 | 61 72 65 20 71 75 69 74 |a types |are quit|
|00002b30| 65 20 64 69 66 66 65 72 | 65 6e 74 20 66 72 6f 6d |e differ|ent from|
|00002b40| 20 77 68 61 74 20 69 73 | 20 66 6f 75 6e 64 0d 69 | what is| found.i|
|00002b50| 6e 20 6c 61 6e 67 75 61 | 67 65 73 20 6c 69 6b 65 |n langua|ges like|
|00002b60| 20 43 2c 20 41 64 61 20 | 6f 72 20 4d 6f 64 75 6c | C, Ada |or Modul|
|00002b70| 61 2d 33 2e 20 20 41 6c | 6c 20 64 61 74 61 20 74 |a-3. Al|l data t|
|00002b80| 79 70 65 73 20 69 6e 20 | 50 79 74 68 6f 6e 2c 20 |ypes in |Python, |
|00002b90| 65 76 65 6e 0d 69 6e 74 | 65 67 65 72 73 2c 20 61 |even.int|egers, a|
|00002ba0| 72 65 20 60 6f 62 6a 65 | 63 74 73 27 2e 20 20 41 |re `obje|cts'. A|
|00002bb0| 6c 6c 20 6f 62 6a 65 63 | 74 73 20 70 61 72 74 69 |ll objec|ts parti|
|00002bc0| 63 69 70 61 74 65 20 69 | 6e 20 61 20 63 6f 6d 6d |cipate i|n a comm|
|00002bd0| 6f 6e 20 67 61 72 62 61 | 67 65 0d 63 6f 6c 6c 65 |on garba|ge.colle|
|00002be0| 63 74 69 6f 6e 20 73 63 | 68 65 6d 65 20 28 63 75 |ction sc|heme (cu|
|00002bf0| 72 72 65 6e 74 6c 79 20 | 69 6d 70 6c 65 6d 65 6e |rrently |implemen|
|00002c00| 74 65 64 20 75 73 69 6e | 67 20 72 65 66 65 72 65 |ted usin|g refere|
|00002c10| 6e 63 65 20 63 6f 75 6e | 74 69 6e 67 29 2e 0d 41 |nce coun|ting)..A|
|00002c20| 73 73 69 67 6e 6d 65 6e | 74 20 69 73 20 63 68 65 |ssignmen|t is che|
|00002c30| 61 70 2c 20 69 6e 64 65 | 70 65 6e 64 65 6e 74 20 |ap, inde|pendent |
|00002c40| 6f 66 20 6f 62 6a 65 63 | 74 20 73 69 7a 65 20 61 |of objec|t size a|
|00002c50| 6e 64 20 74 79 70 65 3a | 20 6f 6e 6c 79 20 61 0d |nd type:| only a.|
|00002c60| 70 6f 69 6e 74 65 72 20 | 74 6f 20 74 68 65 20 61 |pointer |to the a|
|00002c70| 73 73 69 67 6e 65 64 20 | 6f 62 6a 65 63 74 20 69 |ssigned |object i|
|00002c80| 73 20 73 74 6f 72 65 64 | 20 69 6e 20 74 68 65 20 |s stored| in the |
|00002c90| 61 73 73 69 67 6e 65 64 | 2d 74 6f 20 76 61 72 69 |assigned|-to vari|
|00002ca0| 61 62 6c 65 2e 0d 4e 6f | 20 74 79 70 65 20 63 68 |able..No| type ch|
|00002cb0| 65 63 6b 69 6e 67 20 69 | 73 20 70 65 72 66 6f 72 |ecking i|s perfor|
|00002cc0| 6d 65 64 20 6f 6e 20 61 | 73 73 69 67 6e 6d 65 6e |med on a|ssignmen|
|00002cd0| 74 3b 20 6f 6e 6c 79 20 | 73 70 65 63 69 66 69 63 |t; only |specific|
|00002ce0| 20 6f 70 65 72 61 74 69 | 6f 6e 73 0d 6c 69 6b 65 | operati|ons.like|
|00002cf0| 20 61 64 64 69 74 69 6f | 6e 20 74 65 73 74 20 66 | additio|n test f|
|00002d00| 6f 72 20 70 61 72 74 69 | 63 75 6c 61 72 20 6f 70 |or parti|cular op|
|00002d10| 65 72 61 6e 64 20 74 79 | 70 65 73 2e 0d 0d 54 68 |erand ty|pes...Th|
|00002d20| 65 20 62 61 73 69 63 20 | 6f 62 6a 65 63 74 20 74 |e basic |object t|
|00002d30| 79 70 65 73 20 69 6e 20 | 50 79 74 68 6f 6e 20 61 |ypes in |Python a|
|00002d40| 72 65 20 6e 75 6d 62 65 | 72 73 2c 20 73 74 72 69 |re numbe|rs, stri|
|00002d50| 6e 67 73 2c 20 74 75 70 | 6c 65 73 2c 20 6c 69 73 |ngs, tup|les, lis|
|00002d60| 74 73 0d 61 6e 64 20 64 | 69 63 74 69 6f 6e 61 72 |ts.and d|ictionar|
|00002d70| 69 65 73 2e 20 20 53 6f | 6d 65 20 6f 74 68 65 72 |ies. So|me other|
|00002d80| 20 6f 62 6a 65 63 74 20 | 74 79 70 65 73 20 61 72 | object |types ar|
|00002d90| 65 20 6f 70 65 6e 20 66 | 69 6c 65 73 2c 20 66 75 |e open f|iles, fu|
|00002da0| 6e 63 74 69 6f 6e 73 2c | 0d 6d 6f 64 75 6c 65 73 |nctions,|.modules|
|00002db0| 2c 20 63 6c 61 73 73 65 | 73 2c 20 61 6e 64 20 63 |, classe|s, and c|
|00002dc0| 6c 61 73 73 20 69 6e 73 | 74 61 6e 63 65 73 3b 20 |lass ins|tances; |
|00002dd0| 65 76 65 6e 20 74 79 70 | 65 73 20 74 68 65 6d 73 |even typ|es thems|
|00002de0| 65 6c 76 65 73 20 61 72 | 65 0d 72 65 70 72 65 73 |elves ar|e.repres|
|00002df0| 65 6e 74 65 64 20 61 73 | 20 6f 62 6a 65 63 74 73 |ented as| objects|
|00002e00| 2e 20 20 45 78 74 65 6e | 73 69 6f 6e 20 6d 6f 64 |. Exten|sion mod|
|00002e10| 75 6c 65 73 20 77 72 69 | 74 74 65 6e 20 69 6e 20 |ules wri|tten in |
|00002e20| 43 20 63 61 6e 20 64 65 | 66 69 6e 65 0d 61 64 64 |C can de|fine.add|
|00002e30| 69 74 69 6f 6e 61 6c 20 | 6f 62 6a 65 63 74 20 74 |itional |object t|
|00002e40| 79 70 65 73 3b 20 65 78 | 61 6d 70 6c 65 73 20 61 |ypes; ex|amples a|
|00002e50| 72 65 20 6f 62 6a 65 63 | 74 73 20 72 65 70 72 65 |re objec|ts repre|
|00002e60| 73 65 6e 74 69 6e 67 20 | 77 69 6e 64 6f 77 73 20 |senting |windows |
|00002e70| 61 6e 64 0d 41 6d 6f 65 | 62 61 20 63 61 70 61 62 |and.Amoe|ba capab|
|00002e80| 69 6c 69 74 69 65 73 2e | 20 20 46 69 6e 61 6c 6c |ilities.| Finall|
|00002e90| 79 2c 20 74 68 65 20 69 | 6d 70 6c 65 6d 65 6e 74 |y, the i|mplement|
|00002ea0| 61 74 69 6f 6e 20 69 74 | 73 65 6c 66 20 6d 61 6b |ation it|self mak|
|00002eb0| 65 73 20 68 65 61 76 79 | 0d 75 73 65 20 6f 66 20 |es heavy|.use of |
|00002ec0| 6f 62 6a 65 63 74 73 2c | 20 61 6e 64 20 64 65 66 |objects,| and def|
|00002ed0| 69 6e 65 73 20 73 6f 6d | 65 20 70 72 69 76 61 74 |ines som|e privat|
|00002ee0| 65 20 6f 62 6a 65 63 74 | 20 74 79 70 65 73 20 74 |e object| types t|
|00002ef0| 68 61 74 20 61 72 65 6e | 27 74 0d 6e 6f 72 6d 61 |hat aren|'t.norma|
|00002f00| 6c 6c 79 20 76 69 73 69 | 62 6c 65 20 74 6f 20 74 |lly visi|ble to t|
|00002f10| 68 65 20 75 73 65 72 2e | 20 20 54 68 65 72 65 20 |he user.| There |
|00002f20| 69 73 20 6e 6f 20 65 78 | 70 6c 69 63 69 74 20 70 |is no ex|plicit p|
|00002f30| 6f 69 6e 74 65 72 20 74 | 79 70 65 20 69 6e 0d 50 |ointer t|ype in.P|
|00002f40| 79 74 68 6f 6e 2e 0d 0d | 7b 5c 65 6d 20 4e 75 6d |ython...|{\em Num|
|00002f50| 62 65 72 73 7d 2c 20 62 | 6f 74 68 20 69 6e 74 65 |bers}, b|oth inte|
|00002f60| 67 65 72 73 20 61 6e 64 | 20 66 6c 6f 61 74 69 6e |gers and| floatin|
|00002f70| 67 20 70 6f 69 6e 74 2c | 20 61 72 65 20 70 72 65 |g point,| are pre|
|00002f80| 74 74 79 0d 73 74 72 61 | 69 67 68 74 66 6f 72 77 |tty.stra|ightforw|
|00002f90| 61 72 64 2e 20 20 54 68 | 65 20 6e 6f 74 61 74 69 |ard. Th|e notati|
|00002fa0| 6f 6e 20 66 6f 72 20 6e | 75 6d 65 72 69 63 20 6c |on for n|umeric l|
|00002fb0| 69 74 65 72 61 6c 73 20 | 69 73 20 74 68 65 20 73 |iterals |is the s|
|00002fc0| 61 6d 65 20 61 73 20 69 | 6e 0d 43 2c 20 69 6e 63 |ame as i|n.C, inc|
|00002fd0| 6c 75 64 69 6e 67 20 6f | 63 74 61 6c 20 61 6e 64 |luding o|ctal and|
|00002fe0| 20 68 65 78 61 64 65 63 | 69 6d 61 6c 20 69 6e 74 | hexadec|imal int|
|00002ff0| 65 67 65 72 73 3b 20 70 | 72 65 63 69 73 69 6f 6e |egers; p|recision|
|00003000| 20 69 73 20 74 68 65 20 | 73 61 6d 65 20 61 73 0d | is the |same as.|
|00003010| 7b 5c 74 74 20 6c 6f 6e | 67 7d 20 6f 72 20 7b 5c |{\tt lon|g} or {\|
|00003020| 74 74 20 64 6f 75 62 6c | 65 7d 20 69 6e 20 43 5c |tt doubl|e} in C\|
|00003030| 40 2e 20 20 41 20 74 68 | 69 72 64 20 6e 75 6d 65 |@. A th|ird nume|
|00003040| 72 69 63 20 74 79 70 65 | 2c 20 60 6c 6f 6e 67 0d |ric type|, `long.|
|00003050| 69 6e 74 65 67 65 72 27 | 2c 20 77 72 69 74 74 65 |integer'|, writte|
|00003060| 6e 20 77 69 74 68 20 61 | 6e 20 60 4c 27 20 73 75 |n with a|n `L' su|
|00003070| 66 66 69 78 2c 20 63 61 | 6e 20 62 65 20 75 73 65 |ffix, ca|n be use|
|00003080| 64 20 66 6f 72 20 61 72 | 62 69 74 72 61 72 79 0d |d for ar|bitrary.|
|00003090| 70 72 65 63 69 73 69 6f | 6e 20 63 61 6c 63 75 6c |precisio|n calcul|
|000030a0| 61 74 69 6f 6e 73 2e 20 | 20 41 6c 6c 20 61 72 69 |ations. | All ari|
|000030b0| 74 68 6d 65 74 69 63 2c | 20 73 68 69 66 74 69 6e |thmetic,| shiftin|
|000030c0| 67 20 61 6e 64 20 6d 61 | 73 6b 69 6e 67 0d 6f 70 |g and ma|sking.op|
|000030d0| 65 72 61 74 69 6f 6e 73 | 20 66 72 6f 6d 20 43 20 |erations| from C |
|000030e0| 61 72 65 20 73 75 70 70 | 6f 72 74 65 64 2e 0d 0d |are supp|orted...|
|000030f0| 7b 5c 65 6d 20 53 74 72 | 69 6e 67 73 7d 20 61 72 |{\em Str|ings} ar|
|00003100| 65 20 60 70 72 69 6d 69 | 74 69 76 65 27 20 6f 62 |e `primi|tive' ob|
|00003110| 6a 65 63 74 73 20 6a 75 | 73 74 20 6c 69 6b 65 20 |jects ju|st like |
|00003120| 6e 75 6d 62 65 72 73 2e | 20 20 53 74 72 69 6e 67 |numbers.| String|
|00003130| 0d 6c 69 74 65 72 61 6c | 73 20 61 72 65 20 77 72 |.literal|s are wr|
|00003140| 69 74 74 65 6e 20 62 65 | 74 77 65 65 6e 20 73 69 |itten be|tween si|
|00003150| 6e 67 6c 65 20 71 75 6f | 74 65 73 2c 20 75 73 69 |ngle quo|tes, usi|
|00003160| 6e 67 20 73 69 6d 69 6c | 61 72 20 65 73 63 61 70 |ng simil|ar escap|
|00003170| 65 0d 73 65 71 75 65 6e | 63 65 73 20 61 73 20 69 |e.sequen|ces as i|
|00003180| 6e 20 43 5c 40 2e 20 20 | 4f 70 65 72 61 74 69 6f |n C\@. |Operatio|
|00003190| 6e 73 20 61 72 65 20 62 | 75 69 6c 74 20 69 6e 74 |ns are b|uilt int|
|000031a0| 6f 20 74 68 65 20 6c 61 | 6e 67 75 61 67 65 20 74 |o the la|nguage t|
|000031b0| 6f 0d 63 6f 6e 63 61 74 | 65 6e 61 74 65 20 61 6e |o.concat|enate an|
|000031c0| 64 20 74 6f 20 72 65 70 | 6c 69 63 61 74 65 20 73 |d to rep|licate s|
|000031d0| 74 72 69 6e 67 73 2c 20 | 74 6f 20 65 78 74 72 61 |trings, |to extra|
|000031e0| 63 74 20 73 75 62 73 74 | 72 69 6e 67 73 2c 20 65 |ct subst|rings, e|
|000031f0| 74 63 2e 0d 54 68 65 72 | 65 20 69 73 20 6e 6f 20 |tc..Ther|e is no |
|00003200| 6c 69 6d 69 74 20 74 6f | 20 74 68 65 20 6c 65 6e |limit to| the len|
|00003210| 67 74 68 20 6f 66 20 74 | 68 65 20 73 74 72 69 6e |gth of t|he strin|
|00003220| 67 73 20 63 72 65 61 74 | 65 64 20 62 79 20 61 20 |gs creat|ed by a |
|00003230| 70 72 6f 67 72 61 6d 2e | 0d 54 68 65 72 65 20 69 |program.|.There i|
|00003240| 73 20 6e 6f 20 73 65 70 | 61 72 61 74 65 20 63 68 |s no sep|arate ch|
|00003250| 61 72 61 63 74 65 72 20 | 64 61 74 61 20 74 79 70 |aracter |data typ|
|00003260| 65 3b 20 73 74 72 69 6e | 67 73 20 6f 66 20 6c 65 |e; strin|gs of le|
|00003270| 6e 67 74 68 20 6f 6e 65 | 20 64 6f 0d 6e 69 63 65 |ngth one| do.nice|
|00003280| 6c 79 2e 0d 0d 7b 5c 65 | 6d 20 54 75 70 6c 65 73 |ly...{\e|m Tuples|
|00003290| 7d 20 61 72 65 20 61 20 | 77 61 79 20 74 6f 20 60 |} are a |way to `|
|000032a0| 70 61 63 6b 27 20 73 6d | 61 6c 6c 20 61 6d 6f 75 |pack' sm|all amou|
|000032b0| 6e 74 73 20 6f 66 20 68 | 65 74 65 72 6f 67 65 6e |nts of h|eterogen|
|000032c0| 65 6f 75 73 20 64 61 74 | 61 0d 74 6f 67 65 74 68 |eous dat|a.togeth|
|000032d0| 65 72 20 61 6e 64 20 63 | 61 72 72 79 20 74 68 65 |er and c|arry the|
|000032e0| 6d 20 61 72 6f 75 6e 64 | 20 61 73 20 61 20 75 6e |m around| as a un|
|000032f0| 69 74 2e 20 20 55 6e 6c | 69 6b 65 20 73 74 72 75 |it. Unl|ike stru|
|00003300| 63 74 75 72 65 20 6d 65 | 6d 62 65 72 73 20 69 6e |cture me|mbers in|
|00003310| 0d 43 2c 20 74 75 70 6c | 65 20 69 74 65 6d 73 20 |.C, tupl|e items |
|00003320| 61 72 65 20 6e 61 6d 65 | 6c 65 73 73 2e 20 20 50 |are name|less. P|
|00003330| 61 63 6b 69 6e 67 20 61 | 6e 64 20 75 6e 70 61 63 |acking a|nd unpac|
|00003340| 6b 69 6e 67 20 61 73 73 | 69 67 6e 6d 65 6e 74 73 |king ass|ignments|
|00003350| 20 61 6c 6c 6f 77 0d 61 | 63 63 65 73 73 20 74 6f | allow.a|ccess to|
|00003360| 20 74 68 65 20 69 74 65 | 6d 73 2c 20 66 6f 72 20 | the ite|ms, for |
|00003370| 65 78 61 6d 70 6c 65 3a | 0d 5c 62 65 67 69 6e 7b |example:|.\begin{|
|00003380| 76 65 72 62 61 74 69 6d | 7d 0d 78 20 3d 20 27 48 |verbatim|}.x = 'H|
|00003390| 69 27 2c 20 28 31 2c 20 | 32 29 2c 20 27 57 6f 72 |i', (1, |2), 'Wor|
|000033a0| 6c 64 27 20 20 20 23 20 | 78 20 69 73 20 61 20 33 |ld' # |x is a 3|
|000033b0| 2d 69 74 65 6d 20 74 75 | 70 6c 65 2c 0d 20 20 20 |-item tu|ple,. |
|000033c0| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|000033d0| 20 20 20 20 20 20 20 20 | 20 23 20 69 74 73 20 6d | | # its m|
|000033e0| 69 64 64 6c 65 20 69 74 | 65 6d 20 69 73 20 28 31 |iddle it|em is (1|
|000033f0| 2c 20 32 29 0d 70 2c 20 | 71 2c 20 72 20 3d 20 78 |, 2).p, |q, r = x|
|00003400| 20 20 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | | |
|00003410| 20 23 20 75 6e 70 61 63 | 6b 20 78 20 69 6e 74 6f | # unpac|k x into|
|00003420| 20 70 2c 20 71 20 61 6e | 64 20 72 0d 61 2c 20 62 | p, q an|d r.a, b|
|00003430| 20 3d 20 71 20 20 20 20 | 20 20 20 20 20 20 20 20 | = q | |
|00003440| 20 20 20 20 20 20 20 20 | 23 20 75 6e 70 61 63 6b | |# unpack|
|00003450| 20 71 20 69 6e 74 6f 20 | 61 20 61 6e 64 20 62 0d | q into |a and b.|
|00003460| 5c 65 6e 64 7b 76 65 72 | 62 61 74 69 6d 7d 0d 41 |\end{ver|batim}.A|
|00003470| 20 63 6f 6d 62 69 6e 61 | 74 69 6f 6e 20 6f 66 20 | combina|tion of |
|00003480| 70 61 63 6b 69 6e 67 20 | 61 6e 64 20 75 6e 70 61 |packing |and unpa|
|00003490| 63 6b 69 6e 67 20 61 73 | 73 69 67 6e 6d 65 6e 74 |cking as|signment|
|000034a0| 20 63 61 6e 20 62 65 20 | 75 73 65 64 20 61 73 0d | can be |used as.|
|000034b0| 70 61 72 61 6c 6c 65 6c | 20 61 73 73 69 67 6e 6d |parallel| assignm|
|000034c0| 65 6e 74 2c 20 61 6e 64 | 20 69 73 20 69 64 69 6f |ent, and| is idio|
|000034d0| 6d 20 66 6f 72 20 70 65 | 72 6d 75 74 61 74 69 6f |m for pe|rmutatio|
|000034e0| 6e 73 2c 20 65 2e 67 2e | 3a 0d 5c 62 65 67 69 6e |ns, e.g.|:.\begin|
|000034f0| 7b 76 65 72 62 61 74 69 | 6d 7d 0d 70 2c 20 71 20 |{verbati|m}.p, q |
|00003500| 3d 20 71 2c 20 70 20 20 | 20 20 20 20 20 20 20 20 |= q, p | |
|00003510| 20 20 20 20 20 20 20 23 | 20 73 77 61 70 20 77 69 | #| swap wi|
|00003520| 74 68 6f 75 74 20 74 65 | 6d 70 6f 72 61 72 79 0d |thout te|mporary.|
|00003530| 61 2c 20 62 2c 20 63 20 | 3d 20 62 2c 20 63 2c 20 |a, b, c |= b, c, |
|00003540| 61 20 20 20 20 20 20 20 | 20 20 20 20 23 20 63 79 |a | # cy|
|00003550| 63 6c 69 63 20 70 65 72 | 6d 75 74 61 74 69 6f 6e |clic per|mutation|
|00003560| 0d 5c 65 6e 64 7b 76 65 | 72 62 61 74 69 6d 7d 0d |.\end{ve|rbatim}.|
|00003570| 54 75 70 6c 65 73 20 61 | 72 65 20 61 6c 73 6f 20 |Tuples a|re also |
|00003580| 75 73 65 64 20 66 6f 72 | 20 66 75 6e 63 74 69 6f |used for| functio|
|00003590| 6e 20 61 72 67 75 6d 65 | 6e 74 20 6c 69 73 74 73 |n argume|nt lists|
|000035a0| 20 69 66 20 74 68 65 72 | 65 20 69 73 20 6d 6f 72 | if ther|e is mor|
|000035b0| 65 20 74 68 61 6e 0d 6f | 6e 65 20 61 72 67 75 6d |e than.o|ne argum|
|000035c0| 65 6e 74 2e 20 20 41 20 | 74 75 70 6c 65 20 6f 62 |ent. A |tuple ob|
|000035d0| 6a 65 63 74 2c 20 6f 6e | 63 65 20 63 72 65 61 74 |ject, on|ce creat|
|000035e0| 65 64 2c 20 63 61 6e 6e | 6f 74 20 62 65 20 6d 6f |ed, cann|ot be mo|
|000035f0| 64 69 66 69 65 64 3b 20 | 62 75 74 0d 69 74 20 69 |dified; |but.it i|
|00003600| 73 20 65 61 73 79 20 65 | 6e 6f 75 67 68 20 74 6f |s easy e|nough to|
|00003610| 20 75 6e 70 61 63 6b 20 | 69 74 20 61 6e 64 20 63 | unpack |it and c|
|00003620| 72 65 61 74 65 20 61 20 | 6e 65 77 2c 20 6d 6f 64 |reate a |new, mod|
|00003630| 69 66 69 65 64 20 74 75 | 70 6c 65 20 66 72 6f 6d |ified tu|ple from|
|00003640| 0d 74 68 65 20 75 6e 70 | 61 63 6b 65 64 20 69 74 |.the unp|acked it|
|00003650| 65 6d 73 20 61 6e 64 20 | 61 73 73 69 67 6e 20 74 |ems and |assign t|
|00003660| 68 69 73 20 74 6f 20 74 | 68 65 20 76 61 72 69 61 |his to t|he varia|
|00003670| 62 6c 65 20 74 68 61 74 | 20 68 65 6c 64 20 74 68 |ble that| held th|
|00003680| 65 0d 6f 72 69 67 69 6e | 61 6c 20 74 75 70 6c 65 |e.origin|al tuple|
|00003690| 20 6f 62 6a 65 63 74 20 | 28 77 68 69 63 68 20 77 | object |(which w|
|000036a0| 69 6c 6c 20 74 68 65 6e | 20 62 65 20 67 61 72 62 |ill then| be garb|
|000036b0| 61 67 65 2d 63 6f 6c 6c | 65 63 74 65 64 29 2e 0d |age-coll|ected)..|
|000036c0| 0d 7b 5c 65 6d 20 4c 69 | 73 74 73 7d 20 61 72 65 |.{\em Li|sts} are|
|000036d0| 20 61 72 72 61 79 2d 6c | 69 6b 65 20 6f 62 6a 65 | array-l|ike obje|
|000036e0| 63 74 73 2e 20 20 4c 69 | 73 74 20 69 74 65 6d 73 |cts. Li|st items|
|000036f0| 20 6d 61 79 20 62 65 20 | 61 72 62 69 74 72 61 72 | may be |arbitrar|
|00003700| 79 0d 6f 62 6a 65 63 74 | 73 20 61 6e 64 20 63 61 |y.object|s and ca|
|00003710| 6e 20 62 65 20 61 63 63 | 65 73 73 65 64 20 61 6e |n be acc|essed an|
|00003720| 64 20 63 68 61 6e 67 65 | 64 20 75 73 69 6e 67 20 |d change|d using |
|00003730| 73 74 61 6e 64 61 72 64 | 20 73 75 62 73 63 72 69 |standard| subscri|
|00003740| 70 74 69 6f 6e 0d 6e 6f | 74 61 74 69 6f 6e 2e 20 |ption.no|tation. |
|00003750| 20 4c 69 73 74 73 20 73 | 75 70 70 6f 72 74 20 69 | Lists s|upport i|
|00003760| 74 65 6d 20 69 6e 73 65 | 72 74 69 6f 6e 20 61 6e |tem inse|rtion an|
|00003770| 64 20 64 65 6c 65 74 69 | 6f 6e 2c 20 61 6e 64 20 |d deleti|on, and |
|00003780| 63 61 6e 0d 74 68 65 72 | 65 66 6f 72 65 20 62 65 |can.ther|efore be|
|00003790| 20 75 73 65 64 20 61 73 | 20 71 75 65 75 65 73 2c | used as| queues,|
|000037a0| 20 73 74 61 63 6b 73 20 | 65 74 63 2e 3b 20 74 68 | stacks |etc.; th|
|000037b0| 65 72 65 20 69 73 20 6e | 6f 20 6c 69 6d 69 74 20 |ere is n|o limit |
|000037c0| 74 6f 20 74 68 65 69 72 | 0d 73 69 7a 65 2e 0d 0d |to their|.size...|
|000037d0| 53 74 72 69 6e 67 73 2c | 20 74 75 70 6c 65 73 20 |Strings,| tuples |
|000037e0| 61 6e 64 20 6c 69 73 74 | 73 20 74 6f 67 65 74 68 |and list|s togeth|
|000037f0| 65 72 20 61 72 65 20 7b | 5c 65 6d 20 73 65 71 75 |er are {|\em sequ|
|00003800| 65 6e 63 65 7d 20 74 79 | 70 65 73 2e 20 20 54 68 |ence} ty|pes. Th|
|00003810| 65 73 65 0d 73 68 61 72 | 65 20 61 20 63 6f 6d 6d |ese.shar|e a comm|
|00003820| 6f 6e 20 6e 6f 74 61 74 | 69 6f 6e 20 66 6f 72 20 |on notat|ion for |
|00003830| 67 65 6e 65 72 69 63 20 | 6f 70 65 72 61 74 69 6f |generic |operatio|
|00003840| 6e 73 20 6f 6e 20 73 65 | 71 75 65 6e 63 65 73 20 |ns on se|quences |
|00003850| 73 75 63 68 20 61 73 0d | 73 75 62 73 63 72 69 70 |such as.|subscrip|
|00003860| 74 69 6f 6e 2c 20 63 6f | 6e 63 61 74 65 6e 61 74 |tion, co|ncatenat|
|00003870| 69 6f 6e 2c 20 73 6c 69 | 63 69 6e 67 20 28 74 61 |ion, sli|cing (ta|
|00003880| 6b 69 6e 67 20 73 75 62 | 73 65 71 75 65 6e 63 65 |king sub|sequence|
|00003890| 73 29 20 61 6e 64 0d 6d | 65 6d 62 65 72 73 68 69 |s) and.m|embershi|
|000038a0| 70 20 74 65 73 74 73 2e | 20 20 41 73 20 69 6e 20 |p tests.| As in |
|000038b0| 43 2c 20 73 75 62 73 63 | 72 69 70 74 73 20 73 74 |C, subsc|ripts st|
|000038c0| 61 72 74 20 61 74 20 30 | 2e 0d 0d 7b 5c 65 6d 20 |art at 0|...{\em |
|000038d0| 44 69 63 74 69 6f 6e 61 | 72 69 65 73 7d 20 61 72 |Dictiona|ries} ar|
|000038e0| 65 20 60 6d 61 70 70 69 | 6e 67 73 27 20 66 72 6f |e `mappi|ngs' fro|
|000038f0| 6d 20 6f 6e 65 20 64 6f | 6d 61 69 6e 20 74 6f 20 |m one do|main to |
|00003900| 61 6e 6f 74 68 65 72 2e | 20 20 54 68 65 0d 62 61 |another.| The.ba|
|00003910| 73 69 63 20 6f 70 65 72 | 61 74 69 6f 6e 73 20 6f |sic oper|ations o|
|00003920| 6e 20 64 69 63 74 69 6f | 6e 61 72 69 65 73 20 61 |n dictio|naries a|
|00003930| 72 65 20 69 74 65 6d 20 | 69 6e 73 65 72 74 69 6f |re item |insertio|
|00003940| 6e 2c 20 65 78 74 72 61 | 63 74 69 6f 6e 20 61 6e |n, extra|ction an|
|00003950| 64 0d 64 65 6c 65 74 69 | 6f 6e 2c 20 75 73 69 6e |d.deleti|on, usin|
|00003960| 67 20 73 75 62 73 63 72 | 69 70 74 20 6e 6f 74 61 |g subscr|ipt nota|
|00003970| 74 69 6f 6e 20 77 69 74 | 68 20 74 68 65 20 6b 65 |tion wit|h the ke|
|00003980| 79 20 61 73 20 73 75 62 | 73 63 72 69 70 74 2e 20 |y as sub|script. |
|00003990| 20 28 54 68 65 0d 63 75 | 72 72 65 6e 74 20 69 6d | (The.cu|rrent im|
|000039a0| 70 6c 65 6d 65 6e 74 61 | 74 69 6f 6e 20 61 6c 6c |plementa|tion all|
|000039b0| 6f 77 73 20 6f 6e 6c 79 | 20 73 74 72 69 6e 67 73 |ows only| strings|
|000039c0| 20 69 6e 20 74 68 65 20 | 6b 65 79 20 64 6f 6d 61 | in the |key doma|
|000039d0| 69 6e 2c 20 62 75 74 20 | 61 0d 66 75 74 75 72 65 |in, but |a.future|
|000039e0| 20 76 65 72 73 69 6f 6e | 20 6f 66 20 74 68 65 20 | version| of the |
|000039f0| 6c 61 6e 67 75 61 67 65 | 20 6d 61 79 20 72 65 6d |language| may rem|
|00003a00| 6f 76 65 20 74 68 69 73 | 20 72 65 73 74 72 69 63 |ove this| restric|
|00003a10| 74 69 6f 6e 2e 29 0d 0d | 5c 73 75 62 73 65 63 74 |tion.)..|\subsect|
|00003a20| 69 6f 6e 7b 53 74 61 74 | 65 6d 65 6e 74 73 7d 0d |ion{Stat|ements}.|
|00003a30| 0d 50 79 74 68 6f 6e 20 | 68 61 73 20 76 61 72 69 |.Python |has vari|
|00003a40| 6f 75 73 20 6b 69 6e 64 | 73 20 6f 66 20 73 69 6d |ous kind|s of sim|
|00003a50| 70 6c 65 20 73 74 61 74 | 65 6d 65 6e 74 73 2c 20 |ple stat|ements, |
|00003a60| 73 75 63 68 20 61 73 20 | 61 73 73 69 67 6e 6d 65 |such as |assignme|
|00003a70| 6e 74 73 0d 61 6e 64 20 | 7b 5c 74 74 20 70 72 69 |nts.and |{\tt pri|
|00003a80| 6e 74 7d 20 73 74 61 74 | 65 6d 65 6e 74 73 2c 20 |nt} stat|ements, |
|00003a90| 61 6e 64 20 73 65 76 65 | 72 61 6c 20 6b 69 6e 64 |and seve|ral kind|
|00003aa0| 73 20 6f 66 20 63 6f 6d | 70 6f 75 6e 64 20 73 74 |s of com|pound st|
|00003ab0| 61 74 65 6d 65 6e 74 73 | 2c 0d 6c 69 6b 65 20 7b |atements|,.like {|
|00003ac0| 5c 74 74 20 69 66 7d 20 | 61 6e 64 20 7b 5c 74 74 |\tt if} |and {\tt|
|00003ad0| 20 66 6f 72 7d 20 73 74 | 61 74 65 6d 65 6e 74 73 | for} st|atements|
|00003ae0| 2e 20 20 46 6f 72 6d 61 | 6c 6c 79 2c 20 66 75 6e |. Forma|lly, fun|
|00003af0| 63 74 69 6f 6e 0d 64 65 | 66 69 6e 69 74 69 6f 6e |ction.de|finition|
|00003b00| 73 20 61 6e 64 20 7b 5c | 74 74 20 69 6d 70 6f 72 |s and {\|tt impor|
|00003b10| 74 7d 20 73 74 61 74 65 | 6d 65 6e 74 73 20 61 72 |t} state|ments ar|
|00003b20| 65 20 61 6c 73 6f 20 73 | 74 61 74 65 6d 65 6e 74 |e also s|tatement|
|00003b30| 73 2c 20 61 6e 64 20 74 | 68 65 72 65 0d 61 72 65 |s, and t|here.are|
|00003b40| 20 6e 6f 20 72 65 73 74 | 72 69 63 74 69 6f 6e 73 | no rest|rictions|
|00003b50| 20 6f 6e 20 74 68 65 20 | 6f 72 64 65 72 69 6e 67 | on the |ordering|
|00003b60| 20 6f 66 20 73 74 61 74 | 65 6d 65 6e 74 73 20 6f | of stat|ements o|
|00003b70| 72 20 74 68 65 69 72 20 | 6e 65 73 74 69 6e 67 3a |r their |nesting:|
|00003b80| 0d 7b 5c 74 74 20 69 6d | 70 6f 72 74 7d 20 6d 61 |.{\tt im|port} ma|
|00003b90| 79 20 62 65 20 75 73 65 | 64 20 69 6e 73 69 64 65 |y be use|d inside|
|00003ba0| 20 61 20 66 75 6e 63 74 | 69 6f 6e 2c 20 66 75 6e | a funct|ion, fun|
|00003bb0| 63 74 69 6f 6e 73 20 6d | 61 79 20 62 65 20 64 65 |ctions m|ay be de|
|00003bc0| 66 69 6e 65 64 0d 63 6f | 6e 64 69 74 69 6f 6e 61 |fined.co|nditiona|
|00003bd0| 6c 6c 79 20 75 73 69 6e | 67 20 61 6e 20 7b 5c 74 |lly usin|g an {\t|
|00003be0| 74 20 69 66 7d 20 73 74 | 61 74 65 6d 65 6e 74 2c |t if} st|atement,|
|00003bf0| 20 65 74 63 2e 20 20 54 | 68 65 20 65 66 66 65 63 | etc. T|he effec|
|00003c00| 74 20 6f 66 20 61 0d 64 | 65 63 6c 61 72 61 74 69 |t of a.d|eclarati|
|00003c10| 6f 6e 2d 6c 69 6b 65 20 | 73 74 61 74 65 6d 65 6e |on-like |statemen|
|00003c20| 74 20 74 61 6b 65 73 20 | 70 6c 61 63 65 20 6f 6e |t takes |place on|
|00003c30| 6c 79 20 77 68 65 6e 20 | 69 74 20 69 73 20 65 78 |ly when |it is ex|
|00003c40| 65 63 75 74 65 64 2e 0d | 0d 41 6c 6c 20 73 74 61 |ecuted..|.All sta|
|00003c50| 74 65 6d 65 6e 74 73 20 | 65 78 63 65 70 74 20 61 |tements |except a|
|00003c60| 73 73 69 67 6e 6d 65 6e | 74 73 20 61 6e 64 20 65 |ssignmen|ts and e|
|00003c70| 78 70 72 65 73 73 69 6f | 6e 20 73 74 61 74 65 6d |xpressio|n statem|
|00003c80| 65 6e 74 73 20 62 65 67 | 69 6e 20 77 69 74 68 0d |ents beg|in with.|
|00003c90| 61 20 6b 65 79 77 6f 72 | 64 3a 20 74 68 69 73 20 |a keywor|d: this |
|00003ca0| 6d 61 6b 65 73 20 74 68 | 65 20 6c 61 6e 67 75 61 |makes th|e langua|
|00003cb0| 67 65 20 65 61 73 79 20 | 74 6f 20 70 61 72 73 65 |ge easy |to parse|
|00003cc0| 2e 20 20 41 6e 20 6f 76 | 65 72 76 69 65 77 20 6f |. An ov|erview o|
|00003cd0| 66 20 74 68 65 0d 6d 6f | 73 74 20 63 6f 6d 6d 6f |f the.mo|st commo|
|00003ce0| 6e 20 73 74 61 74 65 6d | 65 6e 74 20 66 6f 72 6d |n statem|ent form|
|00003cf0| 73 20 69 6e 20 50 79 74 | 68 6f 6e 20 66 6f 6c 6c |s in Pyt|hon foll|
|00003d00| 6f 77 73 2e 0d 0d 41 6e | 20 7b 5c 65 6d 20 61 73 |ows...An| {\em as|
|00003d10| 73 69 67 6e 6d 65 6e 74 | 7d 20 68 61 73 20 74 68 |signment|} has th|
|00003d20| 65 20 67 65 6e 65 72 61 | 6c 20 66 6f 72 6d 0d 5c |e genera|l form.\|
|00003d30| 76 73 70 61 63 65 7b 5c | 69 74 65 6d 73 65 70 7d |vspace{\|itemsep}|
|00003d40| 0d 0d 5c 6e 6f 69 6e 64 | 65 6e 74 0d 7b 5c 65 6d |..\noind|ent.{\em|
|00003d50| 20 76 61 72 69 61 62 6c | 65 20 24 3d 24 20 76 61 | variabl|e $=$ va|
|00003d60| 72 69 61 62 6c 65 20 24 | 3d 20 2e 2e 2e 20 3d 24 |riable $|= ... =$|
|00003d70| 20 76 61 72 69 61 62 6c | 65 20 24 3d 24 20 65 78 | variabl|e $=$ ex|
|00003d80| 70 72 65 73 73 69 6f 6e | 7d 0d 5c 76 73 70 61 63 |pression|}.\vspac|
|00003d90| 65 7b 5c 69 74 65 6d 73 | 65 70 7d 0d 0d 49 74 20 |e{\items|ep}..It |
|00003da0| 61 73 73 69 67 6e 73 20 | 74 68 65 20 76 61 6c 75 |assigns |the valu|
|00003db0| 65 20 6f 66 20 74 68 65 | 20 65 78 70 72 65 73 73 |e of the| express|
|00003dc0| 69 6f 6e 20 74 6f 20 61 | 6c 6c 20 6c 69 73 74 65 |ion to a|ll liste|
|00003dd0| 64 20 76 61 72 69 61 62 | 6c 65 73 2e 20 20 28 41 |d variab|les. (A|
|00003de0| 73 0d 73 68 6f 77 6e 20 | 69 6e 20 74 68 65 20 73 |s.shown |in the s|
|00003df0| 65 63 74 69 6f 6e 20 6f | 6e 20 74 75 70 6c 65 73 |ection o|n tuples|
|00003e00| 2c 20 76 61 72 69 61 62 | 6c 65 73 20 61 6e 64 20 |, variab|les and |
|00003e10| 65 78 70 72 65 73 73 69 | 6f 6e 73 20 63 61 6e 20 |expressi|ons can |
|00003e20| 69 6e 20 66 61 63 74 0d | 62 65 20 63 6f 6d 6d 61 |in fact.|be comma|
|00003e30| 2d 73 65 70 61 72 61 74 | 65 64 20 6c 69 73 74 73 |-separat|ed lists|
|00003e40| 2e 29 20 20 54 68 65 20 | 61 73 73 69 67 6e 6d 65 |.) The |assignme|
|00003e50| 6e 74 20 6f 70 65 72 61 | 74 6f 72 20 69 73 20 6e |nt opera|tor is n|
|00003e60| 6f 74 20 61 6e 0d 65 78 | 70 72 65 73 73 69 6f 6e |ot an.ex|pression|
|00003e70| 20 6f 70 65 72 61 74 6f | 72 3b 20 74 68 65 72 65 | operato|r; there|
|00003e80| 20 61 72 65 20 6e 6f 20 | 68 6f 72 72 69 62 6c 65 | are no |horrible|
|00003e90| 20 74 68 69 6e 67 73 20 | 69 6e 20 50 79 74 68 6f | things |in Pytho|
|00003ea0| 6e 20 6c 69 6b 65 0d 5c | 62 65 67 69 6e 7b 76 65 |n like.\|begin{ve|
|00003eb0| 72 62 61 74 69 6d 7d 0d | 77 68 69 6c 65 20 28 70 |rbatim}.|while (p|
|00003ec0| 20 3d 20 70 2d 3e 6e 65 | 78 74 29 20 7b 20 2e 2e | = p->ne|xt) { ..|
|00003ed0| 2e 20 7d 0d 5c 65 6e 64 | 7b 76 65 72 62 61 74 69 |. }.\end|{verbati|
|00003ee0| 6d 7d 0d 45 78 70 72 65 | 73 73 69 6f 6e 20 73 79 |m}.Expre|ssion sy|
|00003ef0| 6e 74 61 78 20 69 73 20 | 6d 6f 73 74 6c 79 20 73 |ntax is |mostly s|
|00003f00| 74 72 61 69 67 68 74 66 | 6f 72 77 61 72 64 20 61 |traightf|orward a|
|00003f10| 6e 64 20 77 69 6c 6c 20 | 6e 6f 74 20 62 65 20 65 |nd will |not be e|
|00003f20| 78 70 6c 61 69 6e 65 64 | 0d 69 6e 20 64 65 74 61 |xplained|.in deta|
|00003f30| 69 6c 20 68 65 72 65 2e | 0d 0d 41 6e 20 7b 5c 65 |il here.|..An {\e|
|00003f40| 6d 20 65 78 70 72 65 73 | 73 69 6f 6e 20 73 74 61 |m expres|sion sta|
|00003f50| 74 65 6d 65 6e 74 7d 20 | 69 73 20 6a 75 73 74 20 |tement} |is just |
|00003f60| 61 6e 20 65 78 70 72 65 | 73 73 69 6f 6e 20 6f 6e |an expre|ssion on|
|00003f70| 20 61 20 6c 69 6e 65 20 | 62 79 0d 69 74 73 65 6c | a line |by.itsel|
|00003f80| 66 2e 20 20 54 68 69 73 | 20 77 72 69 74 65 73 20 |f. This| writes |
|00003f90| 74 68 65 20 76 61 6c 75 | 65 20 6f 66 20 74 68 65 |the valu|e of the|
|00003fa0| 20 65 78 70 72 65 73 73 | 69 6f 6e 20 74 6f 20 73 | express|ion to s|
|00003fb0| 74 61 6e 64 61 72 64 20 | 6f 75 74 70 75 74 2c 0d |tandard |output,.|
|00003fc0| 69 6e 20 61 20 73 75 69 | 74 61 62 6c 79 20 75 6e |in a sui|tably un|
|00003fd0| 61 6d 62 69 67 75 6f 75 | 73 20 77 61 79 2c 20 75 |ambiguou|s way, u|
|00003fe0| 6e 6c 65 73 73 20 69 74 | 20 69 73 20 61 20 60 70 |nless it| is a `p|
|00003ff0| 72 6f 63 65 64 75 72 65 | 20 63 61 6c 6c 27 20 28 |rocedure| call' (|
|00004000| 61 0d 66 75 6e 63 74 69 | 6f 6e 20 63 61 6c 6c 20 |a.functi|on call |
|00004010| 74 68 61 74 20 72 65 74 | 75 72 6e 73 20 6e 6f 20 |that ret|urns no |
|00004020| 76 61 6c 75 65 29 2e 20 | 20 57 72 69 74 69 6e 67 |value). | Writing|
|00004030| 20 74 68 65 20 76 61 6c | 75 65 20 69 73 20 75 73 | the val|ue is us|
|00004040| 65 66 75 6c 0d 77 68 65 | 6e 20 50 79 74 68 6f 6e |eful.whe|n Python|
|00004050| 20 69 73 20 75 73 65 64 | 20 69 6e 20 60 63 61 6c | is used| in `cal|
|00004060| 63 75 6c 61 74 6f 72 20 | 6d 6f 64 65 27 2c 20 61 |culator |mode', a|
|00004070| 6e 64 20 72 65 6d 69 6e | 64 73 20 74 68 65 20 70 |nd remin|ds the p|
|00004080| 72 6f 67 72 61 6d 6d 65 | 72 0d 6e 6f 74 20 74 6f |rogramme|r.not to|
|00004090| 20 69 67 6e 6f 72 65 20 | 66 75 6e 63 74 69 6f 6e | ignore |function|
|000040a0| 20 72 65 73 75 6c 74 73 | 2e 0d 0d 54 68 65 20 7b | results|...The {|
|000040b0| 5c 74 74 20 69 66 7d 20 | 73 74 61 74 65 6d 65 6e |\tt if} |statemen|
|000040c0| 74 20 61 6c 6c 6f 77 73 | 20 63 6f 6e 64 69 74 69 |t allows| conditi|
|000040d0| 6f 6e 61 6c 20 65 78 65 | 63 75 74 69 6f 6e 2e 20 |onal exe|cution. |
|000040e0| 20 49 74 20 68 61 73 20 | 6f 70 74 69 6f 6e 61 6c | It has |optional|
|000040f0| 0d 7b 5c 74 74 20 65 6c | 69 66 7d 20 61 6e 64 20 |.{\tt el|if} and |
|00004100| 7b 5c 74 74 20 65 6c 73 | 65 7d 20 70 61 72 74 73 |{\tt els|e} parts|
|00004110| 3b 20 61 20 63 6f 6e 73 | 74 72 75 63 74 20 6c 69 |; a cons|truct li|
|00004120| 6b 65 20 7b 5c 74 74 0d | 69 66 2e 2e 2e 65 6c 69 |ke {\tt.|if...eli|
|00004130| 66 2e 2e 2e 65 6c 69 66 | 2e 2e 2e 65 6c 69 66 2e |f...elif|...elif.|
|00004140| 2e 2e 65 6c 73 65 7d 20 | 63 61 6e 20 62 65 20 75 |..else} |can be u|
|00004150| 73 65 64 20 74 6f 20 63 | 6f 6d 70 65 6e 73 61 74 |sed to c|ompensat|
|00004160| 65 20 66 6f 72 20 74 68 | 65 0d 61 62 73 65 6e 63 |e for th|e.absenc|
|00004170| 65 20 6f 66 20 61 20 7b | 5c 65 6d 20 73 77 69 74 |e of a {|\em swit|
|00004180| 63 68 7d 20 6f 72 20 7b | 5c 65 6d 20 63 61 73 65 |ch} or {|\em case|
|00004190| 7d 20 73 74 61 74 65 6d | 65 6e 74 2e 0d 0d 4c 6f |} statem|ent...Lo|
|000041a0| 6f 70 69 6e 67 20 69 73 | 20 64 6f 6e 65 20 77 69 |oping is| done wi|
|000041b0| 74 68 20 7b 5c 74 74 20 | 77 68 69 6c 65 7d 20 61 |th {\tt |while} a|
|000041c0| 6e 64 20 7b 5c 74 74 20 | 66 6f 72 7d 20 73 74 61 |nd {\tt |for} sta|
|000041d0| 74 65 6d 65 6e 74 73 2e | 20 20 54 68 65 20 6c 61 |tements.| The la|
|000041e0| 74 74 65 72 0d 28 64 65 | 6d 6f 6e 73 74 72 61 74 |tter.(de|monstrat|
|000041f0| 65 64 20 69 6e 20 74 68 | 65 20 60 6c 73 27 20 65 |ed in th|e `ls' e|
|00004200| 78 61 6d 70 6c 65 20 65 | 61 72 6c 69 65 72 29 20 |xample e|arlier) |
|00004210| 69 74 65 72 61 74 65 73 | 20 6f 76 65 72 20 74 68 |iterates| over th|
|00004220| 65 20 65 6c 65 6d 65 6e | 74 73 0d 6f 66 20 61 20 |e elemen|ts.of a |
|00004230| 60 73 65 71 75 65 6e 63 | 65 27 20 28 73 65 65 20 |`sequenc|e' (see |
|00004240| 74 68 65 20 64 69 73 63 | 75 73 73 69 6f 6e 20 6f |the disc|ussion o|
|00004250| 66 20 64 61 74 61 20 74 | 79 70 65 73 20 62 65 6c |f data t|ypes bel|
|00004260| 6f 77 29 2e 20 20 49 74 | 20 69 73 0d 70 6f 73 73 |ow). It| is.poss|
|00004270| 69 62 6c 65 20 74 6f 20 | 74 65 72 6d 69 6e 61 74 |ible to |terminat|
|00004280| 65 20 61 20 6c 6f 6f 70 | 20 77 69 74 68 20 61 20 |e a loop| with a |
|00004290| 7b 5c 74 74 20 62 72 65 | 61 6b 7d 20 73 74 61 74 |{\tt bre|ak} stat|
|000042a0| 65 6d 65 6e 74 20 6f 72 | 20 74 6f 20 73 74 61 72 |ement or| to star|
|000042b0| 74 0d 74 68 65 20 6e 65 | 78 74 20 69 74 65 72 61 |t.the ne|xt itera|
|000042c0| 74 69 6f 6e 20 77 69 74 | 68 20 7b 5c 74 74 20 63 |tion wit|h {\tt c|
|000042d0| 6f 6e 74 69 6e 75 65 7d | 2e 20 20 42 6f 74 68 20 |ontinue}|. Both |
|000042e0| 6c 6f 6f 70 69 6e 67 20 | 73 74 61 74 65 6d 65 6e |looping |statemen|
|000042f0| 74 73 20 68 61 76 65 0d | 61 6e 20 6f 70 74 69 6f |ts have.|an optio|
|00004300| 6e 61 6c 20 7b 5c 74 74 | 20 65 6c 73 65 7d 20 63 |nal {\tt| else} c|
|00004310| 6c 61 75 73 65 20 77 68 | 69 63 68 20 69 73 20 65 |lause wh|ich is e|
|00004320| 78 65 63 75 74 65 64 20 | 61 66 74 65 72 20 74 68 |xecuted |after th|
|00004330| 65 20 6c 6f 6f 70 20 69 | 73 0d 74 65 72 6d 69 6e |e loop i|s.termin|
|00004340| 61 74 65 64 20 6e 6f 72 | 6d 61 6c 6c 79 2c 20 62 |ated nor|mally, b|
|00004350| 75 74 20 73 6b 69 70 70 | 65 64 20 77 68 65 6e 20 |ut skipp|ed when |
|00004360| 69 74 20 69 73 20 74 65 | 72 6d 69 6e 61 74 65 64 |it is te|rminated|
|00004370| 20 62 79 20 7b 5c 74 74 | 20 62 72 65 61 6b 7d 2e | by {\tt| break}.|
|00004380| 0d 54 68 69 73 20 63 61 | 6e 20 62 65 20 68 61 6e |.This ca|n be han|
|00004390| 64 79 20 66 6f 72 20 73 | 65 61 72 63 68 65 73 2c |dy for s|earches,|
|000043a0| 20 74 6f 20 68 61 6e 64 | 6c 65 20 74 68 65 20 63 | to hand|le the c|
|000043b0| 61 73 65 20 74 68 61 74 | 20 74 68 65 20 69 74 65 |ase that| the ite|
|000043c0| 6d 20 69 73 0d 6e 6f 74 | 20 66 6f 75 6e 64 2e 0d |m is.not| found..|
|000043d0| 0d 50 79 74 68 6f 6e 27 | 73 20 7b 5c 65 6d 20 65 |.Python'|s {\em e|
|000043e0| 78 63 65 70 74 69 6f 6e | 7d 20 6d 65 63 68 61 6e |xception|} mechan|
|000043f0| 69 73 6d 20 69 73 20 6d | 6f 64 65 6c 6c 65 64 20 |ism is m|odelled |
|00004400| 61 66 74 65 72 20 74 68 | 61 74 20 6f 66 20 4d 6f |after th|at of Mo|
|00004410| 64 75 6c 61 2d 33 2e 0d | 45 78 63 65 70 74 69 6f |dula-3..|Exceptio|
|00004420| 6e 73 20 61 72 65 20 72 | 61 69 73 65 64 20 62 79 |ns are r|aised by|
|00004430| 20 74 68 65 20 69 6e 74 | 65 72 70 72 65 74 65 72 | the int|erpreter|
|00004440| 20 77 68 65 6e 20 61 6e | 20 69 6c 6c 65 67 61 6c | when an| illegal|
|00004450| 20 6f 70 65 72 61 74 69 | 6f 6e 20 69 73 0d 74 72 | operati|on is.tr|
|00004460| 69 65 64 2e 20 20 49 74 | 20 69 73 20 61 6c 73 6f |ied. It| is also|
|00004470| 20 70 6f 73 73 69 62 6c | 65 20 74 6f 20 65 78 70 | possibl|e to exp|
|00004480| 6c 69 63 69 74 6c 79 20 | 72 61 69 73 65 20 61 6e |licitly |raise an|
|00004490| 20 65 78 63 65 70 74 69 | 6f 6e 20 77 69 74 68 20 | excepti|on with |
|000044a0| 74 68 65 0d 7b 5c 74 74 | 20 72 61 69 73 65 7d 20 |the.{\tt| raise} |
|000044b0| 73 74 61 74 65 6d 65 6e | 74 3a 0d 5c 76 73 70 61 |statemen|t:.\vspa|
|000044c0| 63 65 7b 5c 69 74 65 6d | 73 65 70 7d 0d 0d 5c 6e |ce{\item|sep}..\n|
|000044d0| 6f 69 6e 64 65 6e 74 0d | 7b 5c 74 74 20 72 61 69 |oindent.|{\tt rai|
|000044e0| 73 65 20 7b 5c 65 6d 20 | 65 78 70 72 65 73 73 69 |se {\em |expressi|
|000044f0| 6f 6e 7d 2c 20 7b 5c 65 | 6d 20 65 78 70 72 65 73 |on}, {\e|m expres|
|00004500| 73 69 6f 6e 7d 7d 0d 5c | 76 73 70 61 63 65 7b 5c |sion}}.\|vspace{\|
|00004510| 69 74 65 6d 73 65 70 7d | 0d 0d 54 68 65 20 66 69 |itemsep}|..The fi|
|00004520| 72 73 74 20 65 78 70 72 | 65 73 73 69 6f 6e 20 69 |rst expr|ession i|
|00004530| 64 65 6e 74 69 66 69 65 | 73 20 77 68 69 63 68 20 |dentifie|s which |
|00004540| 65 78 63 65 70 74 69 6f | 6e 20 73 68 6f 75 6c 64 |exceptio|n should|
|00004550| 20 62 65 20 72 61 69 73 | 65 64 3b 0d 74 68 65 72 | be rais|ed;.ther|
|00004560| 65 20 61 72 65 20 73 65 | 76 65 72 61 6c 20 62 75 |e are se|veral bu|
|00004570| 69 6c 74 2d 69 6e 20 65 | 78 63 65 70 74 69 6f 6e |ilt-in e|xception|
|00004580| 73 20 61 6e 64 20 74 68 | 65 20 75 73 65 72 20 6d |s and th|e user m|
|00004590| 61 79 20 64 65 66 69 6e | 65 0d 61 64 64 69 74 69 |ay defin|e.additi|
|000045a0| 6f 6e 61 6c 20 6f 6e 65 | 73 2e 20 20 54 68 65 20 |onal one|s. The |
|000045b0| 73 65 63 6f 6e 64 2c 20 | 6f 70 74 69 6f 6e 61 6c |second, |optional|
|000045c0| 20 65 78 70 72 65 73 73 | 69 6f 6e 20 69 73 20 70 | express|ion is p|
|000045d0| 61 73 73 65 64 20 74 6f | 20 74 68 65 0d 68 61 6e |assed to| the.han|
|000045e0| 64 6c 65 72 2c 20 65 2e | 67 2e 20 61 73 20 61 20 |dler, e.|g. as a |
|000045f0| 64 65 74 61 69 6c 65 64 | 20 65 72 72 6f 72 20 6d |detailed| error m|
|00004600| 65 73 73 61 67 65 2e 0d | 0d 45 78 63 65 70 74 69 |essage..|.Excepti|
|00004610| 6f 6e 73 20 6d 61 79 20 | 62 65 20 68 61 6e 64 6c |ons may |be handl|
|00004620| 65 64 20 28 63 61 75 67 | 68 74 29 20 77 69 74 68 |ed (caug|ht) with|
|00004630| 20 74 68 65 20 7b 5c 74 | 74 20 74 72 79 7d 20 73 | the {\t|t try} s|
|00004640| 74 61 74 65 6d 65 6e 74 | 2c 20 77 68 69 63 68 0d |tatement|, which.|
|00004650| 68 61 73 20 74 68 65 20 | 66 6f 6c 6c 6f 77 69 6e |has the |followin|
|00004660| 67 20 67 65 6e 65 72 61 | 6c 20 66 6f 72 6d 3a 0d |g genera|l form:.|
|00004670| 5c 76 73 70 61 63 65 7b | 5c 69 74 65 6d 73 65 70 |\vspace{|\itemsep|
|00004680| 7d 0d 0d 5c 6e 6f 69 6e | 64 65 6e 74 0d 7b 5c 74 |}..\noin|dent.{\t|
|00004690| 74 0d 5c 62 65 67 69 6e | 7b 74 61 62 75 6c 61 72 |t.\begin|{tabular|
|000046a0| 7d 7b 6c 7d 0d 74 72 79 | 3a 20 7b 5c 65 6d 20 62 |}{l}.try|: {\em b|
|000046b0| 6c 6f 63 6b 7d 20 5c 5c | 0d 65 78 63 65 70 74 20 |lock} \\|.except |
|000046c0| 7b 5c 65 6d 20 65 78 70 | 72 65 73 73 69 6f 6e 7d |{\em exp|ression}|
|000046d0| 2c 20 7b 5c 65 6d 20 76 | 61 72 69 61 62 6c 65 7d |, {\em v|ariable}|
|000046e0| 3a 20 7b 5c 65 6d 20 62 | 6c 6f 63 6b 7d 20 5c 5c |: {\em b|lock} \\|
|000046f0| 0d 65 78 63 65 70 74 20 | 7b 5c 65 6d 20 65 78 70 |.except |{\em exp|
|00004700| 72 65 73 73 69 6f 6e 7d | 2c 20 7b 5c 65 6d 20 76 |ression}|, {\em v|
|00004710| 61 72 69 61 62 6c 65 7d | 3a 20 7b 5c 65 6d 20 62 |ariable}|: {\em b|
|00004720| 6c 6f 63 6b 7d 20 5c 5c | 0d 2e 2e 2e 20 5c 5c 0d |lock} \\|.... \\.|
|00004730| 65 78 63 65 70 74 3a 20 | 7b 5c 65 6d 20 62 6c 6f |except: |{\em blo|
|00004740| 63 6b 7d 0d 5c 65 6e 64 | 7b 74 61 62 75 6c 61 72 |ck}.\end|{tabular|
|00004750| 7d 0d 7d 0d 5c 76 73 70 | 61 63 65 7b 5c 69 74 65 |}.}.\vsp|ace{\ite|
|00004760| 6d 73 65 70 7d 0d 0d 57 | 68 65 6e 20 61 6e 20 65 |msep}..W|hen an e|
|00004770| 78 63 65 70 74 69 6f 6e | 20 69 73 20 72 61 69 73 |xception| is rais|
|00004780| 65 64 20 64 75 72 69 6e | 67 20 65 78 65 63 75 74 |ed durin|g execut|
|00004790| 69 6f 6e 20 6f 66 20 74 | 68 65 20 66 69 72 73 74 |ion of t|he first|
|000047a0| 20 62 6c 6f 63 6b 2c 20 | 61 0d 73 65 61 72 63 68 | block, |a.search|
|000047b0| 20 66 6f 72 20 61 6e 20 | 65 78 63 65 70 74 69 6f | for an |exceptio|
|000047c0| 6e 20 68 61 6e 64 6c 65 | 72 20 73 74 61 72 74 73 |n handle|r starts|
|000047d0| 2e 20 20 54 68 65 20 66 | 69 72 73 74 20 7b 5c 74 |. The f|irst {\t|
|000047e0| 74 20 65 78 63 65 70 74 | 7d 20 63 6c 61 75 73 65 |t except|} clause|
|000047f0| 0d 77 68 6f 73 65 20 7b | 5c 65 6d 20 65 78 70 72 |.whose {|\em expr|
|00004800| 65 73 73 69 6f 6e 7d 20 | 6d 61 74 63 68 65 73 20 |ession} |matches |
|00004810| 74 68 65 20 65 78 63 65 | 70 74 69 6f 6e 20 69 73 |the exce|ption is|
|00004820| 20 65 78 65 63 75 74 65 | 64 2e 20 20 54 68 65 0d | execute|d. The.|
|00004830| 65 78 70 72 65 73 73 69 | 6f 6e 20 6d 61 79 20 73 |expressi|on may s|
|00004840| 70 65 63 69 66 79 20 61 | 20 6c 69 73 74 20 6f 66 |pecify a| list of|
|00004850| 20 65 78 63 65 70 74 69 | 6f 6e 73 20 74 6f 20 6d | excepti|ons to m|
|00004860| 61 74 63 68 20 61 67 61 | 69 6e 73 74 2e 20 20 41 |atch aga|inst. A|
|00004870| 0d 68 61 6e 64 6c 65 72 | 20 77 69 74 68 6f 75 74 |.handler| without|
|00004880| 20 61 6e 20 65 78 70 72 | 65 73 73 69 6f 6e 20 73 | an expr|ession s|
|00004890| 65 72 76 65 73 20 61 73 | 20 61 20 60 63 61 74 63 |erves as| a `catc|
|000048a0| 68 2d 61 6c 6c 27 2e 20 | 20 49 66 20 74 68 65 72 |h-all'. | If ther|
|000048b0| 65 20 69 73 20 6e 6f 0d | 6d 61 74 63 68 2c 20 74 |e is no.|match, t|
|000048c0| 68 65 20 73 65 61 72 63 | 68 20 66 6f 72 20 61 20 |he searc|h for a |
|000048d0| 68 61 6e 64 6c 65 72 20 | 63 6f 6e 74 69 6e 75 65 |handler |continue|
|000048e0| 73 20 77 69 74 68 20 6f | 75 74 65 72 20 7b 5c 74 |s with o|uter {\t|
|000048f0| 74 20 74 72 79 7d 0d 73 | 74 61 74 65 6d 65 6e 74 |t try}.s|tatement|
|00004900| 73 3b 20 69 66 20 6e 6f | 20 6d 61 74 63 68 20 69 |s; if no| match i|
|00004910| 73 20 66 6f 75 6e 64 20 | 6f 6e 20 74 68 65 20 65 |s found |on the e|
|00004920| 6e 74 69 72 65 20 69 6e | 76 6f 63 61 74 69 6f 6e |ntire in|vocation|
|00004930| 20 73 74 61 63 6b 2c 20 | 61 6e 0d 65 72 72 6f 72 | stack, |an.error|
|00004940| 20 6d 65 73 73 61 67 65 | 20 61 6e 64 20 73 74 61 | message| and sta|
|00004950| 63 6b 20 74 72 61 63 65 | 20 61 72 65 20 70 72 69 |ck trace| are pri|
|00004960| 6e 74 65 64 2c 20 61 6e | 64 20 74 68 65 20 70 72 |nted, an|d the pr|
|00004970| 6f 67 72 61 6d 20 69 73 | 0d 74 65 72 6d 69 6e 61 |ogram is|.termina|
|00004980| 74 65 64 20 28 69 6e 74 | 65 72 61 63 74 69 76 65 |ted (int|eractive|
|00004990| 6c 79 2c 20 74 68 65 20 | 69 6e 74 65 72 70 72 65 |ly, the |interpre|
|000049a0| 74 65 72 20 72 65 74 75 | 72 6e 73 20 74 6f 20 69 |ter retu|rns to i|
|000049b0| 74 73 20 6d 61 69 6e 20 | 6c 6f 6f 70 29 2e 0d 0d |ts main |loop)...|
|000049c0| 4e 6f 74 65 20 74 68 61 | 74 20 74 68 65 20 66 6f |Note tha|t the fo|
|000049d0| 72 6d 20 6f 66 20 74 68 | 65 20 7b 5c 74 74 20 65 |rm of th|e {\tt e|
|000049e0| 78 63 65 70 74 7d 20 63 | 6c 61 75 73 65 73 20 65 |xcept} c|lauses e|
|000049f0| 6e 63 6f 75 72 61 67 65 | 73 20 61 20 73 74 79 6c |ncourage|s a styl|
|00004a00| 65 20 6f 66 0d 70 72 6f | 67 72 61 6d 6d 69 6e 67 |e of.pro|gramming|
|00004a10| 20 77 68 65 72 65 62 79 | 20 6f 6e 6c 79 20 73 65 | whereby| only se|
|00004a20| 6c 65 63 74 65 64 20 65 | 78 63 65 70 74 69 6f 6e |lected e|xception|
|00004a30| 73 20 61 72 65 20 63 61 | 75 67 68 74 2c 20 70 61 |s are ca|ught, pa|
|00004a40| 73 73 69 6e 67 0d 75 6e | 61 6e 74 69 63 69 70 61 |ssing.un|anticipa|
|00004a50| 74 65 64 20 65 78 63 65 | 70 74 69 6f 6e 73 20 6f |ted exce|ptions o|
|00004a60| 6e 20 74 6f 20 74 68 65 | 20 63 61 6c 6c 65 72 20 |n to the| caller |
|00004a70| 61 6e 64 20 75 6c 74 69 | 6d 61 74 65 6c 79 20 74 |and ulti|mately t|
|00004a80| 6f 20 74 68 65 20 75 73 | 65 72 2e 0d 54 68 69 73 |o the us|er..This|
|00004a90| 20 69 73 20 70 72 65 66 | 65 72 61 62 6c 65 20 6f | is pref|erable o|
|00004aa0| 76 65 72 20 61 20 73 69 | 6d 70 6c 65 72 20 60 63 |ver a si|mpler `c|
|00004ab0| 61 74 63 68 2d 61 6c 6c | 27 20 65 72 72 6f 72 20 |atch-all|' error |
|00004ac0| 68 61 6e 64 6c 69 6e 67 | 0d 6d 65 63 68 61 6e 69 |handling|.mechani|
|00004ad0| 73 6d 2c 20 77 68 65 72 | 65 20 61 20 73 69 6d 70 |sm, wher|e a simp|
|00004ae0| 6c 69 73 74 69 63 20 68 | 61 6e 64 6c 65 72 20 69 |listic h|andler i|
|00004af0| 6e 74 65 6e 64 65 64 20 | 74 6f 20 63 61 74 63 68 |ntended |to catch|
|00004b00| 20 61 20 73 69 6e 67 6c | 65 20 74 79 70 65 0d 6f | a singl|e type.o|
|00004b10| 66 20 65 72 72 6f 72 20 | 6c 69 6b 65 20 60 66 69 |f error |like `fi|
|00004b20| 6c 65 20 6e 6f 74 20 66 | 6f 75 6e 64 27 20 63 61 |le not f|ound' ca|
|00004b30| 6e 20 65 61 73 69 6c 79 | 20 6d 61 73 6b 20 67 65 |n easily| mask ge|
|00004b40| 6e 75 69 6e 65 20 70 72 | 6f 67 72 61 6d 6d 69 6e |nuine pr|ogrammin|
|00004b50| 67 0d 65 72 72 6f 72 73 | 20 2d 2d 2d 20 65 73 70 |g.errors| --- esp|
|00004b60| 65 63 69 61 6c 6c 79 20 | 69 6e 20 61 20 6c 61 6e |ecially |in a lan|
|00004b70| 67 75 61 67 65 20 6c 69 | 6b 65 20 50 79 74 68 6f |guage li|ke Pytho|
|00004b80| 6e 20 77 68 69 63 68 20 | 72 65 6c 69 65 73 20 73 |n which |relies s|
|00004b90| 74 72 6f 6e 67 6c 79 0d | 6f 6e 20 72 75 6e 2d 74 |trongly.|on run-t|
|00004ba0| 69 6d 65 20 63 68 65 63 | 6b 69 6e 67 20 61 6e 64 |ime chec|king and|
|00004bb0| 20 61 6c 6c 6f 77 73 20 | 74 68 65 20 63 61 74 63 | allows |the catc|
|00004bc0| 68 69 6e 67 20 6f 66 20 | 61 6c 6d 6f 73 74 20 61 |hing of |almost a|
|00004bd0| 6e 79 20 74 79 70 65 20 | 6f 66 0d 65 72 72 6f 72 |ny type |of.error|
|00004be0| 2e 0d 0d 4f 74 68 65 72 | 20 63 6f 6d 6d 6f 6e 20 |...Other| common |
|00004bf0| 73 74 61 74 65 6d 65 6e | 74 20 66 6f 72 6d 73 2c |statemen|t forms,|
|00004c00| 20 77 68 69 63 68 20 77 | 65 20 68 61 76 65 20 61 | which w|e have a|
|00004c10| 6c 72 65 61 64 79 20 65 | 6e 63 6f 75 6e 74 65 72 |lready e|ncounter|
|00004c20| 65 64 2c 20 61 72 65 0d | 66 75 6e 63 74 69 6f 6e |ed, are.|function|
|00004c30| 20 64 65 66 69 6e 69 74 | 69 6f 6e 73 2c 20 7b 5c | definit|ions, {\|
|00004c40| 74 74 20 69 6d 70 6f 72 | 74 7d 20 73 74 61 74 65 |tt impor|t} state|
|00004c50| 6d 65 6e 74 73 20 61 6e | 64 20 7b 5c 74 74 20 70 |ments an|d {\tt p|
|00004c60| 72 69 6e 74 7d 0d 73 74 | 61 74 65 6d 65 6e 74 73 |rint}.st|atements|
|00004c70| 2e 20 20 54 68 65 72 65 | 20 69 73 20 61 6c 73 6f |. There| is also|
|00004c80| 20 61 20 7b 5c 74 74 20 | 64 65 6c 7d 20 73 74 61 | a {\tt |del} sta|
|00004c90| 74 65 6d 65 6e 74 20 74 | 6f 20 64 65 6c 65 74 65 |tement t|o delete|
|00004ca0| 20 6f 6e 65 20 6f 72 20 | 6d 6f 72 65 0d 76 61 72 | one or |more.var|
|00004cb0| 69 61 62 6c 65 73 2c 20 | 61 20 7b 5c 74 74 20 72 |iables, |a {\tt r|
|00004cc0| 65 74 75 72 6e 7d 20 73 | 74 61 74 65 6d 65 6e 74 |eturn} s|tatement|
|00004cd0| 20 74 6f 20 72 65 74 75 | 72 6e 20 66 72 6f 6d 20 | to retu|rn from |
|00004ce0| 61 20 66 75 6e 63 74 69 | 6f 6e 2c 20 61 6e 64 20 |a functi|on, and |
|00004cf0| 61 0d 7b 5c 74 74 20 67 | 6c 6f 62 61 6c 7d 20 73 |a.{\tt g|lobal} s|
|00004d00| 74 61 74 65 6d 65 6e 74 | 20 74 6f 20 61 6c 6c 6f |tatement| to allo|
|00004d10| 77 20 61 73 73 69 67 6e | 6d 65 6e 74 73 20 74 6f |w assign|ments to|
|00004d20| 20 67 6c 6f 62 61 6c 20 | 76 61 72 69 61 62 6c 65 | global |variable|
|00004d30| 73 2e 0d 46 69 6e 61 6c | 6c 79 2c 20 74 68 65 20 |s..Final|ly, the |
|00004d40| 7b 5c 74 74 20 70 61 73 | 73 7d 20 73 74 61 74 65 |{\tt pas|s} state|
|00004d50| 6d 65 6e 74 20 69 73 20 | 61 20 6e 6f 2d 6f 70 2e |ment is |a no-op.|
|00004d60| 0d 0d 5c 73 75 62 73 65 | 63 74 69 6f 6e 7b 45 78 |..\subse|ction{Ex|
|00004d70| 65 63 75 74 69 6f 6e 20 | 4d 6f 64 65 6c 7d 0d 0d |ecution |Model}..|
|00004d80| 41 20 50 79 74 68 6f 6e | 20 70 72 6f 67 72 61 6d |A Python| program|
|00004d90| 20 69 73 20 65 78 65 63 | 75 74 65 64 20 62 79 20 | is exec|uted by |
|00004da0| 61 20 73 74 61 63 6b 2d | 62 61 73 65 64 20 69 6e |a stack-|based in|
|00004db0| 74 65 72 70 72 65 74 65 | 72 2e 0d 0d 57 68 65 6e |terprete|r...When|
|00004dc0| 20 61 20 66 75 6e 63 74 | 69 6f 6e 20 69 73 20 63 | a funct|ion is c|
|00004dd0| 61 6c 6c 65 64 2c 20 61 | 20 6e 65 77 20 60 65 78 |alled, a| new `ex|
|00004de0| 65 63 75 74 69 6f 6e 20 | 65 6e 76 69 72 6f 6e 6d |ecution |environm|
|00004df0| 65 6e 74 27 20 66 6f 72 | 20 69 74 20 69 73 0d 70 |ent' for| it is.p|
|00004e00| 75 73 68 65 64 20 6f 6e | 74 6f 20 74 68 65 20 73 |ushed on|to the s|
|00004e10| 74 61 63 6b 2e 20 20 41 | 6e 20 65 78 65 63 75 74 |tack. A|n execut|
|00004e20| 69 6f 6e 20 65 6e 76 69 | 72 6f 6e 6d 65 6e 74 20 |ion envi|ronment |
|00004e30| 63 6f 6e 74 61 69 6e 73 | 20 28 61 6d 6f 6e 67 20 |contains| (among |
|00004e40| 6f 74 68 65 72 0d 64 61 | 74 61 29 20 70 6f 69 6e |other.da|ta) poin|
|00004e50| 74 65 72 73 20 74 6f 20 | 74 77 6f 20 60 73 79 6d |ters to |two `sym|
|00004e60| 62 6f 6c 20 74 61 62 6c | 65 73 27 20 74 68 61 74 |bol tabl|es' that|
|00004e70| 20 61 72 65 20 75 73 65 | 64 20 74 6f 20 68 6f 6c | are use|d to hol|
|00004e80| 64 20 76 61 72 69 61 62 | 6c 65 73 3a 0d 74 68 65 |d variab|les:.the|
|00004e90| 20 6c 6f 63 61 6c 20 61 | 6e 64 20 74 68 65 20 67 | local a|nd the g|
|00004ea0| 6c 6f 62 61 6c 20 73 79 | 6d 62 6f 6c 20 74 61 62 |lobal sy|mbol tab|
|00004eb0| 6c 65 2e 20 20 54 68 65 | 20 6c 6f 63 61 6c 20 73 |le. The| local s|
|00004ec0| 79 6d 62 6f 6c 20 74 61 | 62 6c 65 0d 63 6f 6e 74 |ymbol ta|ble.cont|
|00004ed0| 61 69 6e 73 20 6c 6f 63 | 61 6c 20 76 61 72 69 61 |ains loc|al varia|
|00004ee0| 62 6c 65 73 20 6f 66 20 | 74 68 65 20 63 75 72 72 |bles of |the curr|
|00004ef0| 65 6e 74 20 66 75 6e 63 | 74 69 6f 6e 20 69 6e 76 |ent func|tion inv|
|00004f00| 6f 63 61 74 69 6f 6e 20 | 28 69 6e 63 6c 75 64 69 |ocation |(includi|
|00004f10| 6e 67 0d 74 68 65 20 66 | 75 6e 63 74 69 6f 6e 20 |ng.the f|unction |
|00004f20| 61 72 67 75 6d 65 6e 74 | 73 29 3b 20 74 68 65 20 |argument|s); the |
|00004f30| 67 6c 6f 62 61 6c 20 73 | 79 6d 62 6f 6c 20 74 61 |global s|ymbol ta|
|00004f40| 62 6c 65 20 63 6f 6e 74 | 61 69 6e 73 20 76 61 72 |ble cont|ains var|
|00004f50| 69 61 62 6c 65 73 0d 64 | 65 66 69 6e 65 64 20 69 |iables.d|efined i|
|00004f60| 6e 20 74 68 65 20 6d 6f | 64 75 6c 65 20 63 6f 6e |n the mo|dule con|
|00004f70| 74 61 69 6e 69 6e 67 20 | 74 68 65 20 63 75 72 72 |taining |the curr|
|00004f80| 65 6e 74 20 66 75 6e 63 | 74 69 6f 6e 2e 0d 0d 54 |ent func|tion...T|
|00004f90| 68 65 20 60 67 6c 6f 62 | 61 6c 27 20 73 79 6d 62 |he `glob|al' symb|
|00004fa0| 6f 6c 20 74 61 62 6c 65 | 20 69 73 20 74 68 75 73 |ol table| is thus|
|00004fb0| 20 6f 6e 6c 79 20 67 6c | 6f 62 61 6c 20 77 69 74 | only gl|obal wit|
|00004fc0| 68 20 72 65 73 70 65 63 | 74 20 74 6f 20 74 68 65 |h respec|t to the|
|00004fd0| 0d 63 75 72 72 65 6e 74 | 20 66 75 6e 63 74 69 6f |.current| functio|
|00004fe0| 6e 2e 20 20 54 68 65 72 | 65 20 61 72 65 20 6e 6f |n. Ther|e are no|
|00004ff0| 20 73 79 73 74 65 6d 2d | 77 69 64 65 20 67 6c 6f | system-|wide glo|
|00005000| 62 61 6c 20 76 61 72 69 | 61 62 6c 65 73 3b 20 75 |bal vari|ables; u|
|00005010| 73 69 6e 67 0d 74 68 65 | 20 7b 5c 74 74 20 69 6d |sing.the| {\tt im|
|00005020| 70 6f 72 74 7d 20 73 74 | 61 74 65 6d 65 6e 74 20 |port} st|atement |
|00005030| 69 74 20 69 73 20 65 61 | 73 79 20 65 6e 6f 75 67 |it is ea|sy enoug|
|00005040| 68 20 74 6f 20 72 65 66 | 65 72 65 6e 63 65 20 76 |h to ref|erence v|
|00005050| 61 72 69 61 62 6c 65 73 | 0d 74 68 61 74 20 61 72 |ariables|.that ar|
|00005060| 65 20 64 65 66 69 6e 65 | 64 20 69 6e 20 6f 74 68 |e define|d in oth|
|00005070| 65 72 20 6d 6f 64 75 6c | 65 73 2e 20 20 41 20 73 |er modul|es. A s|
|00005080| 79 73 74 65 6d 2d 77 69 | 64 65 20 72 65 61 64 2d |ystem-wi|de read-|
|00005090| 6f 6e 6c 79 20 73 79 6d | 62 6f 6c 0d 74 61 62 6c |only sym|bol.tabl|
|000050a0| 65 20 69 73 20 75 73 65 | 64 20 66 6f 72 20 62 75 |e is use|d for bu|
|000050b0| 69 6c 74 2d 69 6e 20 66 | 75 6e 63 74 69 6f 6e 73 |ilt-in f|unctions|
|000050c0| 20 61 6e 64 20 63 6f 6e | 73 74 61 6e 74 73 20 74 | and con|stants t|
|000050d0| 68 6f 75 67 68 2e 0d 0d | 4f 6e 20 61 73 73 69 67 |hough...|On assig|
|000050e0| 6e 6d 65 6e 74 20 74 6f | 20 61 20 76 61 72 69 61 |nment to| a varia|
|000050f0| 62 6c 65 2c 20 62 79 20 | 64 65 66 61 75 6c 74 20 |ble, by |default |
|00005100| 61 6e 20 65 6e 74 72 79 | 20 66 6f 72 20 69 74 20 |an entry| for it |
|00005110| 69 73 20 6d 61 64 65 20 | 69 6e 20 74 68 65 0d 6c |is made |in the.l|
|00005120| 6f 63 61 6c 20 73 79 6d | 62 6f 6c 20 74 61 62 6c |ocal sym|bol tabl|
|00005130| 65 20 6f 66 20 74 68 65 | 20 63 75 72 72 65 6e 74 |e of the| current|
|00005140| 20 65 78 65 63 75 74 69 | 6f 6e 20 65 6e 76 69 72 | executi|on envir|
|00005150| 6f 6e 6d 65 6e 74 2e 20 | 20 54 68 65 20 7b 5c 74 |onment. | The {\t|
|00005160| 74 0d 67 6c 6f 62 61 6c | 7d 20 63 6f 6d 6d 61 6e |t.global|} comman|
|00005170| 64 20 63 61 6e 20 6f 76 | 65 72 72 69 64 65 20 74 |d can ov|erride t|
|00005180| 68 69 73 20 28 69 74 20 | 69 73 20 6e 6f 74 20 65 |his (it |is not e|
|00005190| 6e 6f 75 67 68 20 74 68 | 61 74 20 61 20 67 6c 6f |nough th|at a glo|
|000051a0| 62 61 6c 0d 76 61 72 69 | 61 62 6c 65 20 62 79 20 |bal.vari|able by |
|000051b0| 74 68 65 20 73 61 6d 65 | 20 6e 61 6d 65 20 61 6c |the same| name al|
|000051c0| 72 65 61 64 79 20 65 78 | 69 73 74 73 29 2e 20 20 |ready ex|ists). |
|000051d0| 57 68 65 6e 20 61 20 76 | 61 72 69 61 62 6c 65 27 |When a v|ariable'|
|000051e0| 73 20 76 61 6c 75 65 20 | 69 73 0d 6e 65 65 64 65 |s value |is.neede|
|000051f0| 64 2c 20 69 74 20 69 73 | 20 73 65 61 72 63 68 65 |d, it is| searche|
|00005200| 64 20 66 69 72 73 74 20 | 69 6e 20 74 68 65 20 6c |d first |in the l|
|00005210| 6f 63 61 6c 20 73 79 6d | 62 6f 6c 20 74 61 62 6c |ocal sym|bol tabl|
|00005220| 65 2c 20 74 68 65 6e 20 | 69 6e 20 74 68 65 0d 67 |e, then |in the.g|
|00005230| 6c 6f 62 61 6c 20 6f 6e | 65 2c 20 61 6e 64 20 66 |lobal on|e, and f|
|00005240| 69 6e 61 6c 6c 79 20 69 | 6e 20 74 68 65 20 73 79 |inally i|n the sy|
|00005250| 6d 62 6f 6c 20 74 61 62 | 6c 65 20 63 6f 6e 74 61 |mbol tab|le conta|
|00005260| 69 6e 69 6e 67 20 62 75 | 69 6c 74 2d 69 6e 0d 66 |ining bu|ilt-in.f|
|00005270| 75 6e 63 74 69 6f 6e 73 | 20 61 6e 64 20 63 6f 6e |unctions| and con|
|00005280| 73 74 61 6e 74 73 2e 0d | 0d 54 68 65 20 74 65 72 |stants..|.The ter|
|00005290| 6d 20 60 76 61 72 69 61 | 62 6c 65 27 20 69 6e 20 |m `varia|ble' in |
|000052a0| 74 68 69 73 20 63 6f 6e | 74 65 78 74 20 72 65 66 |this con|text ref|
|000052b0| 65 72 73 20 74 6f 20 61 | 6e 79 20 6e 61 6d 65 3a |ers to a|ny name:|
|000052c0| 20 66 75 6e 63 74 69 6f | 6e 73 20 61 6e 64 0d 69 | functio|ns and.i|
|000052d0| 6d 70 6f 72 74 65 64 20 | 6d 6f 64 75 6c 65 73 20 |mported |modules |
|000052e0| 61 72 65 20 73 65 61 72 | 63 68 65 64 20 69 6e 20 |are sear|ched in |
|000052f0| 65 78 61 63 74 6c 79 20 | 74 68 65 20 73 61 6d 65 |exactly |the same|
|00005300| 20 77 61 79 2e 20 20 0d | 0d 4e 61 6d 65 73 20 64 | way. .|.Names d|
|00005310| 65 66 69 6e 65 64 20 69 | 6e 20 61 20 6d 6f 64 75 |efined i|n a modu|
|00005320| 6c 65 27 73 20 73 79 6d | 62 6f 6c 20 74 61 62 6c |le's sym|bol tabl|
|00005330| 65 20 73 75 72 76 69 76 | 65 20 75 6e 74 69 6c 20 |e surviv|e until |
|00005340| 74 68 65 20 65 6e 64 20 | 6f 66 20 74 68 65 0d 70 |the end |of the.p|
|00005350| 72 6f 67 72 61 6d 2e 20 | 20 54 68 69 73 20 61 70 |rogram. | This ap|
|00005360| 70 72 6f 78 69 6d 61 74 | 65 73 20 74 68 65 20 73 |proximat|es the s|
|00005370| 65 6d 61 6e 74 69 63 73 | 20 6f 66 20 66 69 6c 65 |emantics| of file|
|00005380| 2d 73 74 61 74 69 63 20 | 67 6c 6f 62 61 6c 0d 76 |-static |global.v|
|00005390| 61 72 69 61 62 6c 65 73 | 20 69 6e 20 43 20 6f 72 |ariables| in C or|
|000053a0| 20 6d 6f 64 75 6c 65 20 | 76 61 72 69 61 62 6c 65 | module |variable|
|000053b0| 73 20 69 6e 20 4d 6f 64 | 75 6c 61 2d 33 2e 20 20 |s in Mod|ula-3. |
|000053c0| 41 20 6d 6f 64 75 6c 65 | 20 69 73 0d 69 6e 69 74 |A module| is.init|
|000053d0| 69 61 6c 69 7a 65 64 20 | 74 68 65 20 66 69 72 73 |ialized |the firs|
|000053e0| 74 20 74 69 6d 65 20 69 | 74 20 69 73 20 69 6d 70 |t time i|t is imp|
|000053f0| 6f 72 74 65 64 2c 20 62 | 79 20 65 78 65 63 75 74 |orted, b|y execut|
|00005400| 69 6e 67 20 74 68 65 20 | 74 65 78 74 20 6f 66 0d |ing the |text of.|
|00005410| 74 68 65 20 6d 6f 64 75 | 6c 65 20 61 73 20 61 20 |the modu|le as a |
|00005420| 70 61 72 61 6d 65 74 65 | 72 6c 65 73 73 20 66 75 |paramete|rless fu|
|00005430| 6e 63 74 69 6f 6e 20 77 | 68 6f 73 65 20 6c 6f 63 |nction w|hose loc|
|00005440| 61 6c 20 61 6e 64 20 67 | 6c 6f 62 61 6c 20 73 79 |al and g|lobal sy|
|00005450| 6d 62 6f 6c 0d 74 61 62 | 6c 65 73 20 61 72 65 20 |mbol.tab|les are |
|00005460| 74 68 65 20 73 61 6d 65 | 2c 20 73 6f 20 6e 61 6d |the same|, so nam|
|00005470| 65 73 20 61 72 65 20 64 | 65 66 69 6e 65 64 20 69 |es are d|efined i|
|00005480| 6e 20 6d 6f 64 75 6c 65 | 27 73 20 73 79 6d 62 6f |n module|'s symbo|
|00005490| 6c 20 74 61 62 6c 65 2e | 0d 28 4d 6f 64 75 6c 65 |l table.|.(Module|
|000054a0| 73 20 69 6d 70 6c 65 6d | 65 6e 74 65 64 20 69 6e |s implem|ented in|
|000054b0| 20 43 20 68 61 76 65 20 | 61 6e 6f 74 68 65 72 20 | C have |another |
|000054c0| 77 61 79 20 74 6f 20 64 | 65 66 69 6e 65 20 73 79 |way to d|efine sy|
|000054d0| 6d 62 6f 6c 73 2e 29 0d | 0d 41 20 50 79 74 68 6f |mbols.).|.A Pytho|
|000054e0| 6e 20 6d 61 69 6e 20 70 | 72 6f 67 72 61 6d 20 69 |n main p|rogram i|
|000054f0| 73 20 72 65 61 64 20 66 | 72 6f 6d 20 73 74 61 6e |s read f|rom stan|
|00005500| 64 61 72 64 20 69 6e 70 | 75 74 20 6f 72 20 66 72 |dard inp|ut or fr|
|00005510| 6f 6d 20 61 20 73 63 72 | 69 70 74 0d 66 69 6c 65 |om a scr|ipt.file|
|00005520| 20 70 61 73 73 65 64 20 | 61 73 20 61 6e 20 61 72 | passed |as an ar|
|00005530| 67 75 6d 65 6e 74 20 74 | 6f 20 74 68 65 20 69 6e |gument t|o the in|
|00005540| 74 65 72 70 72 65 74 65 | 72 2e 20 20 49 74 20 69 |terprete|r. It i|
|00005550| 73 20 65 78 65 63 75 74 | 65 64 20 61 73 20 69 66 |s execut|ed as if|
|00005560| 0d 61 6e 20 61 6e 6f 6e | 79 6d 6f 75 73 20 6d 6f |.an anon|ymous mo|
|00005570| 64 75 6c 65 20 77 61 73 | 20 69 6d 70 6f 72 74 65 |dule was| importe|
|00005580| 64 2e 20 20 53 69 6e 63 | 65 20 7b 5c 74 74 20 69 |d. Sinc|e {\tt i|
|00005590| 6d 70 6f 72 74 7d 20 73 | 74 61 74 65 6d 65 6e 74 |mport} s|tatement|
|000055a0| 73 20 61 72 65 0d 65 78 | 65 63 75 74 65 64 20 6c |s are.ex|ecuted l|
|000055b0| 69 6b 65 20 61 6c 6c 20 | 6f 74 68 65 72 20 73 74 |ike all |other st|
|000055c0| 61 74 65 6d 65 6e 74 73 | 2c 20 74 68 65 20 69 6e |atements|, the in|
|000055d0| 69 74 69 61 6c 69 7a 61 | 74 69 6f 6e 20 6f 72 64 |itializa|tion ord|
|000055e0| 65 72 20 6f 66 20 74 68 | 65 0d 6d 6f 64 75 6c 65 |er of th|e.module|
|000055f0| 73 20 75 73 65 64 20 69 | 6e 20 61 20 70 72 6f 67 |s used i|n a prog|
|00005600| 72 61 6d 20 69 73 20 64 | 65 66 69 6e 65 64 20 62 |ram is d|efined b|
|00005610| 79 20 74 68 65 20 66 6c | 6f 77 20 6f 66 20 63 6f |y the fl|ow of co|
|00005620| 6e 74 72 6f 6c 20 74 68 | 72 6f 75 67 68 0d 74 68 |ntrol th|rough.th|
|00005630| 65 20 70 72 6f 67 72 61 | 6d 2e 0d 0d 54 68 65 20 |e progra|m...The |
|00005640| 60 61 74 74 72 69 62 75 | 74 65 27 20 6e 6f 74 61 |`attribu|te' nota|
|00005650| 74 69 6f 6e 20 7b 5c 65 | 6d 20 6d 2e 6e 61 6d 65 |tion {\e|m m.name|
|00005660| 7d 2c 20 77 68 65 72 65 | 20 7b 5c 65 6d 20 6d 7d |}, where| {\em m}|
|00005670| 20 69 73 20 61 20 6d 6f | 64 75 6c 65 2c 0d 61 63 | is a mo|dule,.ac|
|00005680| 63 65 73 73 65 73 20 74 | 68 65 20 73 79 6d 62 6f |cesses t|he symbo|
|00005690| 6c 20 7b 5c 65 6d 20 6e | 61 6d 65 7d 20 69 6e 20 |l {\em n|ame} in |
|000056a0| 74 68 61 74 20 6d 6f 64 | 75 6c 65 27 73 20 73 79 |that mod|ule's sy|
|000056b0| 6d 62 6f 6c 20 74 61 62 | 6c 65 2e 20 20 49 74 20 |mbol tab|le. It |
|000056c0| 63 61 6e 0d 62 65 20 61 | 73 73 69 67 6e 65 64 20 |can.be a|ssigned |
|000056d0| 74 6f 20 61 73 20 77 65 | 6c 6c 2e 20 20 54 68 69 |to as we|ll. Thi|
|000056e0| 73 20 69 73 20 69 6e 20 | 66 61 63 74 20 61 20 73 |s is in |fact a s|
|000056f0| 70 65 63 69 61 6c 20 63 | 61 73 65 20 6f 66 20 74 |pecial c|ase of t|
|00005700| 68 65 0d 63 6f 6e 73 74 | 72 75 63 74 20 7b 5c 65 |he.const|ruct {\e|
|00005710| 6d 20 78 2e 6e 61 6d 65 | 7d 20 77 68 65 72 65 20 |m x.name|} where |
|00005720| 7b 5c 65 6d 20 78 7d 20 | 64 65 6e 6f 74 65 73 20 |{\em x} |denotes |
|00005730| 61 6e 20 61 72 62 69 74 | 72 61 72 79 20 6f 62 6a |an arbit|rary obj|
|00005740| 65 63 74 3b 20 74 68 65 | 0d 74 79 70 65 20 6f 66 |ect; the|.type of|
|00005750| 20 7b 5c 65 6d 20 78 7d | 20 64 65 74 65 72 6d 69 | {\em x}| determi|
|00005760| 6e 65 73 20 68 6f 77 20 | 74 68 69 73 20 69 73 20 |nes how |this is |
|00005770| 74 6f 20 62 65 20 69 6e | 74 65 72 70 72 65 74 65 |to be in|terprete|
|00005780| 64 2c 20 61 6e 64 20 77 | 68 61 74 0d 61 73 73 69 |d, and w|hat.assi|
|00005790| 67 6e 6d 65 6e 74 20 74 | 6f 20 69 74 20 6d 65 61 |gnment t|o it mea|
|000057a0| 6e 73 2e 0d 0d 46 6f 72 | 20 69 6e 73 74 61 6e 63 |ns...For| instanc|
|000057b0| 65 2c 20 77 68 65 6e 20 | 7b 5c 74 74 20 61 7d 20 |e, when |{\tt a} |
|000057c0| 69 73 20 61 20 6c 69 73 | 74 20 6f 62 6a 65 63 74 |is a lis|t object|
|000057d0| 2c 20 7b 5c 74 74 20 61 | 2e 61 70 70 65 6e 64 7d |, {\tt a|.append}|
|000057e0| 20 79 69 65 6c 64 73 20 | 61 0d 62 75 69 6c 74 2d | yields |a.built-|
|000057f0| 69 6e 20 60 6d 65 74 68 | 6f 64 27 20 6f 62 6a 65 |in `meth|od' obje|
|00005800| 63 74 20 77 68 69 63 68 | 2c 20 77 68 65 6e 20 63 |ct which|, when c|
|00005810| 61 6c 6c 65 64 2c 20 61 | 70 70 65 6e 64 73 20 61 |alled, a|ppends a|
|00005820| 6e 20 69 74 65 6d 20 74 | 6f 20 7b 5c 74 74 20 61 |n item t|o {\tt a|
|00005830| 7d 2e 0d 28 49 66 20 7b | 5c 74 74 20 61 7d 20 61 |}..(If {|\tt a} a|
|00005840| 6e 64 20 7b 5c 74 74 20 | 62 7d 20 61 72 65 20 64 |nd {\tt |b} are d|
|00005850| 69 73 74 69 6e 63 74 20 | 6c 69 73 74 20 6f 62 6a |istinct |list obj|
|00005860| 65 63 74 73 2c 20 7b 5c | 74 74 20 61 2e 61 70 70 |ects, {\|tt a.app|
|00005870| 65 6e 64 7d 20 61 6e 64 | 0d 7b 5c 74 74 20 62 2e |end} and|.{\tt b.|
|00005880| 61 70 70 65 6e 64 7d 20 | 61 72 65 20 64 69 73 74 |append} |are dist|
|00005890| 69 6e 67 75 69 73 68 61 | 62 6c 65 20 6d 65 74 68 |inguisha|ble meth|
|000058a0| 6f 64 20 6f 62 6a 65 63 | 74 73 2e 29 20 20 4e 6f |od objec|ts.) No|
|000058b0| 72 6d 61 6c 6c 79 2c 20 | 69 6e 0d 73 74 61 74 65 |rmally, |in.state|
|000058c0| 6d 65 6e 74 73 20 6c 69 | 6b 65 20 7b 5c 74 74 20 |ments li|ke {\tt |
|000058d0| 61 2e 61 70 70 65 6e 64 | 28 78 29 7d 2c 20 74 68 |a.append|(x)}, th|
|000058e0| 65 20 6d 65 74 68 6f 64 | 20 6f 62 6a 65 63 74 20 |e method| object |
|000058f0| 7b 5c 74 74 20 61 2e 61 | 70 70 65 6e 64 7d 20 69 |{\tt a.a|ppend} i|
|00005900| 73 0d 63 61 6c 6c 65 64 | 20 61 6e 64 20 74 68 65 |s.called| and the|
|00005910| 6e 20 64 69 73 63 61 72 | 64 65 64 2c 20 62 75 74 |n discar|ded, but|
|00005920| 20 74 68 69 73 20 69 73 | 20 61 20 6d 61 74 74 65 | this is| a matte|
|00005930| 72 20 6f 66 20 63 6f 6e | 76 65 6e 74 69 6f 6e 2e |r of con|vention.|
|00005940| 0d 0d 4c 69 73 74 20 61 | 74 74 72 69 62 75 74 65 |..List a|ttribute|
|00005950| 73 20 61 72 65 20 72 65 | 61 64 2d 6f 6e 6c 79 20 |s are re|ad-only |
|00005960| 2d 2d 2d 20 74 68 65 20 | 75 73 65 72 20 63 61 6e |--- the |user can|
|00005970| 6e 6f 74 20 64 65 66 69 | 6e 65 20 6e 65 77 20 6c |not defi|ne new l|
|00005980| 69 73 74 0d 6d 65 74 68 | 6f 64 73 2e 20 20 53 6f |ist.meth|ods. So|
|00005990| 6d 65 20 6f 62 6a 65 63 | 74 73 2c 20 6c 69 6b 65 |me objec|ts, like|
|000059a0| 20 6e 75 6d 62 65 72 73 | 20 61 6e 64 20 73 74 72 | numbers| and str|
|000059b0| 69 6e 67 73 2c 20 68 61 | 76 65 20 6e 6f 20 61 74 |ings, ha|ve no at|
|000059c0| 74 72 69 62 75 74 65 73 | 0d 61 74 20 61 6c 6c 2e |tributes|.at all.|
|000059d0| 20 20 4c 69 6b 65 20 61 | 6c 6c 20 74 79 70 65 20 | Like a|ll type |
|000059e0| 63 68 65 63 6b 69 6e 67 | 20 69 6e 20 50 79 74 68 |checking| in Pyth|
|000059f0| 6f 6e 2c 20 74 68 65 20 | 6d 65 61 6e 69 6e 67 20 |on, the |meaning |
|00005a00| 6f 66 20 61 6e 20 61 74 | 74 72 69 62 75 74 65 0d |of an at|tribute.|
|00005a10| 69 73 20 64 65 74 65 72 | 6d 69 6e 65 64 20 61 74 |is deter|mined at|
|00005a20| 20 72 75 6e 2d 74 69 6d | 65 20 2d 2d 2d 20 77 68 | run-tim|e --- wh|
|00005a30| 65 6e 20 74 68 65 20 70 | 61 72 73 65 72 20 73 65 |en the p|arser se|
|00005a40| 65 73 20 7b 5c 65 6d 20 | 78 2e 6e 61 6d 65 7d 2c |es {\em |x.name},|
|00005a50| 20 69 74 0d 68 61 73 20 | 6e 6f 20 69 64 65 61 20 | it.has |no idea |
|00005a60| 6f 66 20 74 68 65 20 74 | 79 70 65 20 6f 66 20 7b |of the t|ype of {|
|00005a70| 5c 65 6d 20 78 7d 2e 20 | 20 4e 6f 74 65 20 74 68 |\em x}. | Note th|
|00005a80| 61 74 20 7b 5c 65 6d 20 | 78 7d 20 68 65 72 65 20 |at {\em |x} here |
|00005a90| 64 6f 65 73 20 6e 6f 74 | 0d 68 61 76 65 20 74 6f |does not|.have to|
|00005aa0| 20 62 65 20 61 20 76 61 | 72 69 61 62 6c 65 20 2d | be a va|riable -|
|00005ab0| 2d 2d 20 69 74 20 63 61 | 6e 20 62 65 20 61 6e 20 |-- it ca|n be an |
|00005ac0| 61 72 62 69 74 72 61 72 | 79 20 28 70 65 72 68 61 |arbitrar|y (perha|
|00005ad0| 70 73 0d 70 61 72 65 6e | 74 68 65 73 69 7a 65 64 |ps.paren|thesized|
|00005ae0| 29 20 65 78 70 72 65 73 | 73 69 6f 6e 2e 0d 0d 47 |) expres|sion...G|
|00005af0| 69 76 65 6e 20 74 68 65 | 20 66 6c 65 78 69 62 69 |iven the| flexibi|
|00005b00| 6c 69 74 79 20 6f 66 20 | 74 68 65 20 61 74 74 72 |lity of |the attr|
|00005b10| 69 62 75 74 65 20 6e 6f | 74 61 74 69 6f 6e 2c 20 |ibute no|tation, |
|00005b20| 6f 6e 65 20 69 73 20 74 | 65 6d 70 74 65 64 20 74 |one is t|empted t|
|00005b30| 6f 20 75 73 65 0d 6d 65 | 74 68 6f 64 73 20 74 6f |o use.me|thods to|
|00005b40| 20 72 65 70 6c 61 63 65 | 20 61 6c 6c 20 73 74 61 | replace| all sta|
|00005b50| 6e 64 61 72 64 20 6f 70 | 65 72 61 74 69 6f 6e 73 |ndard op|erations|
|00005b60| 2e 20 20 59 65 74 2c 20 | 50 79 74 68 6f 6e 20 68 |. Yet, |Python h|
|00005b70| 61 73 20 6b 65 70 74 20 | 61 0d 73 6d 61 6c 6c 20 |as kept |a.small |
|00005b80| 72 65 70 65 72 74 6f 69 | 72 65 20 6f 66 20 62 75 |repertoi|re of bu|
|00005b90| 69 6c 74 2d 69 6e 20 66 | 75 6e 63 74 69 6f 6e 73 |ilt-in f|unctions|
|00005ba0| 20 6c 69 6b 65 20 7b 5c | 74 74 20 6c 65 6e 28 29 | like {\|tt len()|
|00005bb0| 7d 20 61 6e 64 20 7b 5c | 74 74 0d 61 62 73 28 29 |} and {\|tt.abs()|
|00005bc0| 7d 2e 20 20 54 68 65 20 | 72 65 61 73 6f 6e 20 69 |}. The |reason i|
|00005bd0| 73 20 74 68 61 74 20 69 | 6e 20 73 6f 6d 65 20 63 |s that i|n some c|
|00005be0| 61 73 65 73 20 74 68 65 | 20 66 75 6e 63 74 69 6f |ases the| functio|
|00005bf0| 6e 20 6e 6f 74 61 74 69 | 6f 6e 20 69 73 0d 6d 6f |n notati|on is.mo|
|00005c00| 72 65 20 66 61 6d 69 6c | 69 61 72 20 74 68 61 6e |re famil|iar than|
|00005c10| 20 74 68 65 20 6d 65 74 | 68 6f 64 20 6e 6f 74 61 | the met|hod nota|
|00005c20| 74 69 6f 6e 3b 20 6a 75 | 73 74 20 6c 69 6b 65 20 |tion; ju|st like |
|00005c30| 70 72 6f 67 72 61 6d 73 | 20 77 6f 75 6c 64 0d 62 |programs| would.b|
|00005c40| 65 63 6f 6d 65 20 6c 65 | 73 73 20 72 65 61 64 61 |ecome le|ss reada|
|00005c50| 62 6c 65 20 69 66 20 61 | 6c 6c 20 69 6e 66 69 78 |ble if a|ll infix|
|00005c60| 20 6f 70 65 72 61 74 6f | 72 73 20 77 65 72 65 20 | operato|rs were |
|00005c70| 72 65 70 6c 61 63 65 64 | 20 62 79 20 66 75 6e 63 |replaced| by func|
|00005c80| 74 69 6f 6e 0d 63 61 6c | 6c 73 2c 20 74 68 65 79 |tion.cal|ls, they|
|00005c90| 20 77 6f 75 6c 64 20 62 | 65 63 6f 6d 65 20 6c 65 | would b|ecome le|
|00005ca0| 73 73 20 72 65 61 64 61 | 62 6c 65 20 69 66 20 61 |ss reada|ble if a|
|00005cb0| 6c 6c 20 66 75 6e 63 74 | 69 6f 6e 20 63 61 6c 6c |ll funct|ion call|
|00005cc0| 73 20 68 61 64 20 74 6f | 20 62 65 0d 72 65 70 6c |s had to| be.repl|
|00005cd0| 61 63 65 64 20 62 79 20 | 6d 65 74 68 6f 64 20 63 |aced by |method c|
|00005ce0| 61 6c 6c 73 20 28 61 6e | 64 20 76 69 63 65 20 76 |alls (an|d vice v|
|00005cf0| 65 72 73 61 21 29 2e 0d | 0d 54 68 65 20 63 68 6f |ersa!)..|.The cho|
|00005d00| 69 63 65 20 77 68 65 74 | 68 65 72 20 74 6f 20 6d |ice whet|her to m|
|00005d10| 61 6b 65 20 73 6f 6d 65 | 74 68 69 6e 67 20 61 20 |ake some|thing a |
|00005d20| 62 75 69 6c 74 2d 69 6e | 20 66 75 6e 63 74 69 6f |built-in| functio|
|00005d30| 6e 20 6f 72 20 61 20 6d | 65 74 68 6f 64 0d 69 73 |n or a m|ethod.is|
|00005d40| 20 61 20 6d 61 74 74 65 | 72 20 6f 66 20 74 61 73 | a matte|r of tas|
|00005d50| 74 65 2e 20 20 46 6f 72 | 20 61 72 69 74 68 6d 65 |te. For| arithme|
|00005d60| 74 69 63 20 61 6e 64 20 | 73 74 72 69 6e 67 20 6f |tic and |string o|
|00005d70| 70 65 72 61 74 69 6f 6e | 73 2c 20 66 75 6e 63 74 |peration|s, funct|
|00005d80| 69 6f 6e 0d 6e 6f 74 61 | 74 69 6f 6e 20 69 73 20 |ion.nota|tion is |
|00005d90| 70 72 65 66 65 72 72 65 | 64 2c 20 73 69 6e 63 65 |preferre|d, since|
|00005da0| 20 66 72 65 71 75 65 6e | 74 6c 79 20 74 68 65 20 | frequen|tly the |
|00005db0| 61 72 67 75 6d 65 6e 74 | 20 74 6f 20 73 75 63 68 |argument| to such|
|00005dc0| 20 61 6e 0d 6f 70 65 72 | 61 74 69 6f 6e 20 69 73 | an.oper|ation is|
|00005dd0| 20 61 6e 20 65 78 70 72 | 65 73 73 69 6f 6e 20 75 | an expr|ession u|
|00005de0| 73 69 6e 67 20 69 6e 66 | 69 78 20 6e 6f 74 61 74 |sing inf|ix notat|
|00005df0| 69 6f 6e 2c 20 61 73 20 | 69 6e 20 7b 5c 74 74 20 |ion, as |in {\tt |
|00005e00| 61 62 73 28 61 2b 62 29 | 7d 3b 0d 74 68 69 73 20 |abs(a+b)|};.this |
|00005e10| 64 65 66 69 6e 69 74 65 | 6c 79 20 6c 6f 6f 6b 73 |definite|ly looks|
|00005e20| 20 62 65 74 74 65 72 20 | 74 68 61 6e 20 7b 5c 74 | better |than {\t|
|00005e30| 74 20 28 61 2b 62 29 2e | 61 62 73 28 29 7d 2e 20 |t (a+b).|abs()}. |
|00005e40| 20 54 68 65 20 63 68 6f | 69 63 65 0d 62 65 74 77 | The cho|ice.betw|
|00005e50| 65 65 6e 20 6d 61 6b 65 | 20 73 6f 6d 65 74 68 69 |een make| somethi|
|00005e60| 6e 67 20 61 20 62 75 69 | 6c 74 2d 69 6e 20 66 75 |ng a bui|lt-in fu|
|00005e70| 6e 63 74 69 6f 6e 20 6f | 72 20 61 20 66 75 6e 63 |nction o|r a func|
|00005e80| 74 69 6f 6e 20 64 65 66 | 69 6e 65 64 20 69 6e 20 |tion def|ined in |
|00005e90| 61 0d 62 75 69 6c 74 2d | 69 6e 20 6d 65 74 68 6f |a.built-|in metho|
|00005ea0| 64 20 28 72 65 71 75 69 | 72 69 6e 67 20 7b 5c 74 |d (requi|ring {\t|
|00005eb0| 74 20 69 6d 70 6f 72 74 | 7d 29 20 69 73 20 73 69 |t import|}) is si|
|00005ec0| 6d 69 6c 61 72 6c 79 20 | 67 75 69 64 65 64 20 62 |milarly |guided b|
|00005ed0| 79 0d 69 6e 74 75 69 74 | 69 6f 6e 3b 20 61 6c 6c |y.intuit|ion; all|
|00005ee0| 20 69 6e 20 61 6c 6c 2c | 20 6f 6e 6c 79 20 66 75 | in all,| only fu|
|00005ef0| 6e 63 74 69 6f 6e 73 20 | 6e 65 65 64 65 64 20 62 |nctions |needed b|
|00005f00| 79 20 60 67 65 6e 65 72 | 61 6c 27 20 70 72 6f 67 |y `gener|al' prog|
|00005f10| 72 61 6d 6d 69 6e 67 0d | 74 65 63 68 6e 69 71 75 |ramming.|techniqu|
|00005f20| 65 73 20 61 72 65 20 62 | 75 69 6c 74 2d 69 6e 20 |es are b|uilt-in |
|00005f30| 66 75 6e 63 74 69 6f 6e | 73 2e 0d 0d 5c 73 75 62 |function|s...\sub|
|00005f40| 73 65 63 74 69 6f 6e 7b | 43 6c 61 73 73 65 73 7d |section{|Classes}|
|00005f50| 0d 0d 50 79 74 68 6f 6e | 20 68 61 73 20 61 20 63 |..Python| has a c|
|00005f60| 6c 61 73 73 20 6d 65 63 | 68 61 6e 69 73 6d 20 64 |lass mec|hanism d|
|00005f70| 69 73 74 69 6e 63 74 20 | 66 72 6f 6d 20 74 68 65 |istinct |from the|
|00005f80| 20 6f 62 6a 65 63 74 2d | 6f 72 69 65 6e 74 61 74 | object-|orientat|
|00005f90| 69 6f 6e 0d 61 6c 72 65 | 61 64 79 20 65 78 70 6c |ion.alre|ady expl|
|00005fa0| 61 69 6e 65 64 2e 20 20 | 41 20 63 6c 61 73 73 20 |ained. |A class |
|00005fb0| 69 6e 20 50 79 74 68 6f | 6e 20 69 73 20 6e 6f 74 |in Pytho|n is not|
|00005fc0| 20 6d 75 63 68 20 6d 6f | 72 65 20 74 68 61 6e 20 | much mo|re than |
|00005fd0| 61 0d 63 6f 6c 6c 65 63 | 74 69 6f 6e 20 6f 66 20 |a.collec|tion of |
|00005fe0| 6d 65 74 68 6f 64 73 20 | 61 6e 64 20 61 20 77 61 |methods |and a wa|
|00005ff0| 79 20 74 6f 20 63 72 65 | 61 74 65 20 63 6c 61 73 |y to cre|ate clas|
|00006000| 73 20 69 6e 73 74 61 6e | 63 65 73 2e 20 20 43 6c |s instan|ces. Cl|
|00006010| 61 73 73 0d 6d 65 74 68 | 6f 64 73 20 61 72 65 20 |ass.meth|ods are |
|00006020| 6f 72 64 69 6e 61 72 79 | 20 66 75 6e 63 74 69 6f |ordinary| functio|
|00006030| 6e 73 20 77 68 6f 73 65 | 20 66 69 72 73 74 20 70 |ns whose| first p|
|00006040| 61 72 61 6d 65 74 65 72 | 20 69 73 20 74 68 65 20 |arameter| is the |
|00006050| 63 6c 61 73 73 0d 69 6e | 73 74 61 6e 63 65 3b 20 |class.in|stance; |
|00006060| 74 68 65 79 20 61 72 65 | 20 63 61 6c 6c 65 64 20 |they are| called |
|00006070| 75 73 69 6e 67 20 74 68 | 65 20 6d 65 74 68 6f 64 |using th|e method|
|00006080| 20 6e 6f 74 61 74 69 6f | 6e 2e 0d 0d 46 6f 72 20 | notatio|n...For |
|00006090| 69 6e 73 74 61 6e 63 65 | 2c 20 61 20 63 6c 61 73 |instance|, a clas|
|000060a0| 73 20 63 61 6e 20 62 65 | 20 64 65 66 69 6e 65 64 |s can be| defined|
|000060b0| 20 61 73 20 66 6f 6c 6c | 6f 77 73 3a 0d 5c 62 65 | as foll|ows:.\be|
|000060c0| 67 69 6e 7b 76 65 72 62 | 61 74 69 6d 7d 0d 63 6c |gin{verb|atim}.cl|
|000060d0| 61 73 73 20 46 6f 6f 3a | 0d 20 20 20 64 65 66 20 |ass Foo:|. def |
|000060e0| 6d 65 74 68 31 28 73 65 | 6c 66 2c 20 61 72 67 29 |meth1(se|lf, arg)|
|000060f0| 3a 20 2e 2e 2e 0d 20 20 | 20 64 65 66 20 6d 65 74 |: .... | def met|
|00006100| 68 32 28 73 65 6c 66 29 | 3a 20 2e 2e 2e 0d 5c 65 |h2(self)|: ....\e|
|00006110| 6e 64 7b 76 65 72 62 61 | 74 69 6d 7d 0d 41 20 63 |nd{verba|tim}.A c|
|00006120| 6c 61 73 73 20 69 6e 73 | 74 61 6e 63 65 20 69 73 |lass ins|tance is|
|00006130| 20 63 72 65 61 74 65 64 | 20 62 79 0d 7b 5c 74 74 | created| by.{\tt|
|00006140| 20 78 20 3d 20 46 6f 6f | 28 29 7d 0d 61 6e 64 20 | x = Foo|()}.and |
|00006150| 69 74 73 20 6d 65 74 68 | 6f 64 73 20 63 61 6e 20 |its meth|ods can |
|00006160| 62 65 20 63 61 6c 6c 65 | 64 20 74 68 75 73 3a 0d |be calle|d thus:.|
|00006170| 5c 62 65 67 69 6e 7b 76 | 65 72 62 61 74 69 6d 7d |\begin{v|erbatim}|
|00006180| 0d 78 2e 6d 65 74 68 31 | 28 27 48 69 20 54 68 65 |.x.meth1|('Hi The|
|00006190| 72 65 21 27 29 0d 78 2e | 6d 65 74 68 32 28 29 0d |re!').x.|meth2().|
|000061a0| 5c 65 6e 64 7b 76 65 72 | 62 61 74 69 6d 7d 0d 54 |\end{ver|batim}.T|
|000061b0| 68 65 20 66 75 6e 63 74 | 69 6f 6e 73 20 75 73 65 |he funct|ions use|
|000061c0| 64 20 61 73 20 6d 65 74 | 68 6f 64 73 20 61 72 65 |d as met|hods are|
|000061d0| 20 61 6c 73 6f 20 61 76 | 61 69 6c 61 62 6c 65 20 | also av|ailable |
|000061e0| 61 73 20 61 74 74 72 69 | 62 75 74 65 73 20 6f 66 |as attri|butes of|
|000061f0| 20 74 68 65 0d 63 6c 61 | 73 73 20 6f 62 6a 65 63 | the.cla|ss objec|
|00006200| 74 2c 20 61 6e 64 20 74 | 68 65 20 61 62 6f 76 65 |t, and t|he above|
|00006210| 20 6d 65 74 68 6f 64 20 | 63 61 6c 6c 73 20 63 6f | method |calls co|
|00006220| 75 6c 64 20 61 6c 73 6f | 20 68 61 76 65 20 62 65 |uld also| have be|
|00006230| 65 6e 20 77 72 69 74 74 | 65 6e 0d 61 73 20 66 6f |en writt|en.as fo|
|00006240| 6c 6c 6f 77 73 3a 0d 5c | 62 65 67 69 6e 7b 76 65 |llows:.\|begin{ve|
|00006250| 72 62 61 74 69 6d 7d 0d | 46 6f 6f 2e 6d 65 74 68 |rbatim}.|Foo.meth|
|00006260| 31 28 78 2c 20 27 48 69 | 20 54 68 65 72 65 21 27 |1(x, 'Hi| There!'|
|00006270| 29 0d 46 6f 6f 2e 6d 65 | 74 68 32 28 78 29 0d 5c |).Foo.me|th2(x).\|
|00006280| 65 6e 64 7b 76 65 72 62 | 61 74 69 6d 7d 0d 43 6c |end{verb|atim}.Cl|
|00006290| 61 73 73 20 6d 65 74 68 | 6f 64 73 20 63 61 6e 20 |ass meth|ods can |
|000062a0| 73 74 6f 72 65 20 69 6e | 73 74 61 6e 63 65 20 64 |store in|stance d|
|000062b0| 61 74 61 20 62 79 20 61 | 73 73 69 67 6e 69 6e 67 |ata by a|ssigning|
|000062c0| 20 74 6f 20 69 6e 73 74 | 61 6e 63 65 20 64 61 74 | to inst|ance dat|
|000062d0| 61 0d 61 74 74 72 69 62 | 75 74 65 73 2c 20 65 2e |a.attrib|utes, e.|
|000062e0| 67 2e 3a 0d 5c 62 65 67 | 69 6e 7b 76 65 72 62 61 |g.:.\beg|in{verba|
|000062f0| 74 69 6d 7d 0d 73 65 6c | 66 2e 73 69 7a 65 20 3d |tim}.sel|f.size =|
|00006300| 20 31 30 30 0d 73 65 6c | 66 2e 74 69 74 6c 65 20 | 100.sel|f.title |
|00006310| 3d 20 27 44 65 61 72 20 | 4a 6f 68 6e 27 0d 5c 65 |= 'Dear |John'.\e|
|00006320| 6e 64 7b 76 65 72 62 61 | 74 69 6d 7d 0d 44 61 74 |nd{verba|tim}.Dat|
|00006330| 61 20 61 74 74 72 69 62 | 75 74 65 73 20 64 6f 20 |a attrib|utes do |
|00006340| 6e 6f 74 20 68 61 76 65 | 20 74 6f 20 62 65 20 64 |not have| to be d|
|00006350| 65 63 6c 61 72 65 64 3b | 20 61 73 20 77 69 74 68 |eclared;| as with|
|00006360| 20 6c 6f 63 61 6c 20 76 | 61 72 69 61 62 6c 65 73 | local v|ariables|
|00006370| 2c 0d 74 68 65 79 20 73 | 70 72 69 6e 67 20 69 6e |,.they s|pring in|
|00006380| 74 6f 20 65 78 69 73 74 | 65 6e 63 65 20 77 68 65 |to exist|ence whe|
|00006390| 6e 20 61 73 73 69 67 6e | 65 64 20 74 6f 2e 20 20 |n assign|ed to. |
|000063a0| 49 74 20 69 73 20 61 20 | 6d 61 74 74 65 72 20 6f |It is a |matter o|
|000063b0| 66 0d 64 69 73 63 72 65 | 74 69 6f 6e 20 74 6f 20 |f.discre|tion to |
|000063c0| 61 76 6f 69 64 20 6e 61 | 6d 65 20 63 6f 6e 66 6c |avoid na|me confl|
|000063d0| 69 63 74 73 20 77 69 74 | 68 20 6d 65 74 68 6f 64 |icts wit|h method|
|000063e0| 20 6e 61 6d 65 73 2e 20 | 20 54 68 69 73 20 66 61 | names. | This fa|
|000063f0| 63 69 6c 69 74 79 0d 69 | 73 20 61 6c 73 6f 20 61 |cility.i|s also a|
+--------+-------------------------+-------------------------+--------+--------+
Only 25.0 KB of data is shown above.