home *** CD-ROM | disk | FTP | other *** search
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: tex
Confidence | Program | Detection | Match Type | Support
|
---|
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
| 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[LF]
| default (weak)
|
|
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 0a 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 0a 0a |ox{.18ex|}{++}}..|
|00000050| 5c 74 69 74 6c 65 7b 0a | 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 0a 7d 0a 0a 5c 61 | 75 74 68 6f 72 7b 0a 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 0a 09 44 65 70 | 74 2e 20 41 41 2c 20 43 | \\..Dep|t. AA, C|
|000000d0| 57 49 2c 20 50 2e 4f 2e | 20 42 6f 78 20 39 34 30 |WI, P.O.| Box 940|
|000000e0| 37 39 20 5c 5c 0a 09 31 | 30 39 30 20 47 42 20 41 |79 \\..1|090 GB A|
|000000f0| 6d 73 74 65 72 64 61 6d | 2c 20 54 68 65 20 4e 65 |msterdam|, The Ne|
|00000100| 74 68 65 72 6c 61 6e 64 | 73 20 5c 5c 0a 09 45 2d |therland|s \\..E-|
|00000110| 6d 61 69 6c 3a 20 7b 5c | 74 74 20 67 75 69 64 6f |mail: {\|tt guido|
|00000120| 40 63 77 69 2e 6e 6c 7d | 0a 5c 61 6e 64 0a 09 4a |@cwi.nl}|.\and..J|
|00000130| 65 6c 6b 65 20 64 65 20 | 42 6f 65 72 20 5c 5c 0a |elke de |Boer \\.|
|00000140| 09 48 49 4f 20 45 6e 73 | 63 68 65 64 65 3b 20 50 |.HIO Ens|chede; P|
|00000150| 2e 4f 2e 42 6f 78 20 31 | 33 32 36 20 5c 5c 0a 09 |.O.Box 1|326 \\..|
|00000160| 37 35 30 30 20 42 48 20 | 20 45 6e 73 63 68 65 64 |7500 BH | Ensched|
|00000170| 65 2c 20 54 68 65 20 4e | 65 74 68 65 72 6c 61 6e |e, The N|etherlan|
|00000180| 64 73 0a 7d 0a 0a 5c 62 | 65 67 69 6e 7b 64 6f 63 |ds.}..\b|egin{doc|
|00000190| 75 6d 65 6e 74 7d 0a 0a | 5c 6d 61 6b 65 74 69 74 |ument}..|\maketit|
|000001a0| 6c 65 0a 0a 5c 62 65 67 | 69 6e 7b 61 62 73 74 72 |le..\beg|in{abstr|
|000001b0| 61 63 74 7d 0a 54 68 69 | 73 20 70 61 70 65 72 20 |act}.Thi|s paper |
|000001c0| 64 65 73 63 72 69 62 65 | 73 20 68 6f 77 20 74 77 |describe|s how tw|
|000001d0| 6f 20 74 6f 6f 6c 73 20 | 74 68 61 74 20 77 65 72 |o tools |that wer|
|000001e0| 65 20 64 65 76 65 6c 6f | 70 65 64 20 71 75 69 74 |e develo|ped quit|
|000001f0| 65 0a 69 6e 64 65 70 65 | 6e 64 65 6e 74 6c 79 20 |e.indepe|ndently |
|00000200| 67 61 69 6e 65 64 20 69 | 6e 20 70 6f 77 65 72 20 |gained i|n power |
|00000210| 62 79 20 61 20 77 65 6c | 6c 2d 64 65 73 69 67 6e |by a wel|l-design|
|00000220| 65 64 20 63 6f 6e 6e 65 | 63 74 69 6f 6e 20 62 65 |ed conne|ction be|
|00000230| 74 77 65 65 6e 0a 74 68 | 65 6d 2e 20 20 54 68 65 |tween.th|em. The|
|00000240| 20 74 6f 6f 6c 73 20 61 | 72 65 20 50 79 74 68 6f | tools a|re Pytho|
|00000250| 6e 2c 20 61 6e 20 69 6e | 74 65 72 70 72 65 74 65 |n, an in|terprete|
|00000260| 64 20 70 72 6f 74 6f 74 | 79 70 69 6e 67 20 6c 61 |d protot|yping la|
|00000270| 6e 67 75 61 67 65 2c 20 | 61 6e 64 0a 41 49 4c 2c |nguage, |and.AIL,|
|00000280| 20 61 20 52 65 6d 6f 74 | 65 20 50 72 6f 63 65 64 | a Remot|e Proced|
|00000290| 75 72 65 20 43 61 6c 6c | 20 73 74 75 62 20 67 65 |ure Call| stub ge|
|000002a0| 6e 65 72 61 74 6f 72 2e | 20 20 54 68 65 20 63 6f |nerator.| The co|
|000002b0| 6e 74 65 78 74 20 69 73 | 20 41 6d 6f 65 62 61 2c |ntext is| Amoeba,|
|000002c0| 20 61 0a 77 65 6c 6c 2d | 6b 6e 6f 77 6e 20 64 69 | a.well-|known di|
|000002d0| 73 74 72 69 62 75 74 65 | 64 20 6f 70 65 72 61 74 |stribute|d operat|
|000002e0| 69 6e 67 20 73 79 73 74 | 65 6d 20 64 65 76 65 6c |ing syst|em devel|
|000002f0| 6f 70 65 64 20 6a 6f 69 | 6e 74 6c 79 20 62 79 20 |oped joi|ntly by |
|00000300| 74 68 65 20 46 72 65 65 | 0a 55 6e 69 76 65 72 73 |the Free|.Univers|
|00000310| 69 74 79 20 61 6e 64 20 | 43 57 49 20 69 6e 20 41 |ity and |CWI in A|
|00000320| 6d 73 74 65 72 64 61 6d | 2e 0a 0a 41 73 20 61 20 |msterdam|...As a |
|00000330| 63 6f 6e 73 65 71 75 65 | 6e 63 65 20 6f 66 20 74 |conseque|nce of t|
|00000340| 68 65 69 72 20 69 6e 74 | 65 67 72 61 74 69 6f 6e |heir int|egration|
|00000350| 2c 20 62 6f 74 68 20 74 | 6f 6f 6c 73 20 68 61 76 |, both t|ools hav|
|00000360| 65 20 70 72 6f 66 69 74 | 65 64 3a 0a 50 79 74 68 |e profit|ed:.Pyth|
|00000370| 6f 6e 20 67 61 69 6e 65 | 64 20 75 73 61 62 69 6c |on gaine|d usabil|
|00000380| 69 74 79 20 77 68 65 6e | 20 75 73 65 64 20 77 69 |ity when| used wi|
|00000390| 74 68 20 41 6d 6f 65 62 | 61 20 2d 2d 2d 20 66 6f |th Amoeb|a --- fo|
|000003a0| 72 20 77 68 69 63 68 20 | 69 74 20 77 61 73 20 6e |r which |it was n|
|000003b0| 6f 74 0a 73 70 65 63 69 | 66 69 63 61 6c 6c 79 20 |ot.speci|fically |
|000003c0| 64 65 76 65 6c 6f 70 65 | 64 20 2d 2d 2d 20 61 6e |develope|d --- an|
|000003d0| 64 20 41 49 4c 20 75 73 | 65 72 73 20 6e 6f 77 20 |d AIL us|ers now |
|000003e0| 68 61 76 65 20 61 20 70 | 6f 77 65 72 66 75 6c 0a |have a p|owerful.|
|000003f0| 69 6e 74 65 72 61 63 74 | 69 76 65 20 74 6f 6f 6c |interact|ive tool|
|00000400| 20 74 6f 20 74 65 73 74 | 20 73 65 72 76 65 72 73 | to test| servers|
|00000410| 20 61 6e 64 20 74 6f 20 | 65 78 70 65 72 69 6d 65 | and to |experime|
|00000420| 6e 74 20 77 69 74 68 20 | 6e 65 77 0a 63 6c 69 65 |nt with |new.clie|
|00000430| 6e 74 2f 73 65 72 76 65 | 72 20 69 6e 74 65 72 66 |nt/serve|r interf|
|00000440| 61 63 65 73 2e 25 0a 5c | 66 6f 6f 74 6e 6f 74 65 |aces.%.\|footnote|
|00000450| 7b 0a 41 6e 20 65 61 72 | 6c 69 65 72 20 76 65 72 |{.An ear|lier ver|
|00000460| 73 69 6f 6e 20 6f 66 20 | 74 68 69 73 20 70 61 70 |sion of |this pap|
|00000470| 65 72 20 77 61 73 20 70 | 72 65 73 65 6e 74 65 64 |er was p|resented|
|00000480| 20 61 74 20 74 68 65 20 | 53 70 72 69 6e 67 20 31 | at the |Spring 1|
|00000490| 39 39 31 0a 45 75 72 4f | 70 65 6e 20 43 6f 6e 66 |991.EurO|pen Conf|
|000004a0| 65 72 65 6e 63 65 20 69 | 6e 20 54 72 6f 6d 73 7b |erence i|n Troms{|
|000004b0| 5c 6f 7d 20 75 6e 64 65 | 72 20 74 68 65 20 74 69 |\o} unde|r the ti|
|000004c0| 74 6c 65 20 60 60 4c 69 | 6e 6b 69 6e 67 20 61 20 |tle ``Li|nking a |
|000004d0| 53 74 75 62 0a 47 65 6e | 65 72 61 74 6f 72 20 28 |Stub.Gen|erator (|
|000004e0| 41 49 4c 29 20 74 6f 20 | 61 20 50 72 6f 74 6f 74 |AIL) to |a Protot|
|000004f0| 79 70 69 6e 67 20 4c 61 | 6e 67 75 61 67 65 20 28 |yping La|nguage (|
|00000500| 50 79 74 68 6f 6e 29 2e | 27 27 0a 7d 0a 5c 65 6e |Python).|''.}.\en|
|00000510| 64 7b 61 62 73 74 72 61 | 63 74 7d 0a 0a 5c 73 65 |d{abstra|ct}..\se|
|00000520| 63 74 69 6f 6e 7b 49 6e | 74 72 6f 64 75 63 74 69 |ction{In|troducti|
|00000530| 6f 6e 7d 0a 0a 52 65 6d | 6f 74 65 20 50 72 6f 63 |on}..Rem|ote Proc|
|00000540| 65 64 75 72 65 20 43 61 | 6c 6c 20 28 52 50 43 29 |edure Ca|ll (RPC)|
|00000550| 20 69 6e 74 65 72 66 61 | 63 65 73 2c 20 75 73 65 | interfa|ces, use|
|00000560| 64 20 69 6e 20 64 69 73 | 74 72 69 62 75 74 65 64 |d in dis|tributed|
|00000570| 20 73 79 73 74 65 6d 73 | 0a 6c 69 6b 65 20 41 6d | systems|.like Am|
|00000580| 6f 65 62 61 0a 5c 63 69 | 74 65 7b 41 6d 6f 65 62 |oeba.\ci|te{Amoeb|
|00000590| 61 3a 49 45 45 45 2c 41 | 6d 6f 65 62 61 3a 43 41 |a:IEEE,A|moeba:CA|
|000005a0| 43 4d 7d 2c 0a 68 61 76 | 65 20 61 20 6d 75 63 68 |CM},.hav|e a much|
|000005b0| 20 6d 6f 72 65 20 63 6f | 6e 63 72 65 74 65 20 63 | more co|ncrete c|
|000005c0| 68 61 72 61 63 74 65 72 | 20 74 68 61 6e 20 6c 6f |haracter| than lo|
|000005d0| 63 61 6c 20 70 72 6f 63 | 65 64 75 72 65 20 63 61 |cal proc|edure ca|
|000005e0| 6c 6c 0a 69 6e 74 65 72 | 66 61 63 65 73 20 69 6e |ll.inter|faces in|
|000005f0| 20 74 72 61 64 69 74 69 | 6f 6e 61 6c 20 73 79 73 | traditi|onal sys|
|00000600| 74 65 6d 73 2e 20 20 42 | 65 63 61 75 73 65 20 63 |tems. B|ecause c|
|00000610| 6c 69 65 6e 74 73 20 61 | 6e 64 20 73 65 72 76 65 |lients a|nd serve|
|00000620| 72 73 20 6d 61 79 0a 72 | 75 6e 20 6f 6e 20 64 69 |rs may.r|un on di|
|00000630| 66 66 65 72 65 6e 74 20 | 6d 61 63 68 69 6e 65 73 |fferent |machines|
|00000640| 2c 20 77 69 74 68 20 70 | 6f 73 73 69 62 6c 79 20 |, with p|ossibly |
|00000650| 64 69 66 66 65 72 65 6e | 74 20 77 6f 72 64 20 73 |differen|t word s|
|00000660| 69 7a 65 2c 20 62 79 74 | 65 0a 6f 72 64 65 72 2c |ize, byt|e.order,|
|00000670| 20 65 74 63 2e 2c 20 6d | 75 63 68 20 63 61 72 65 | etc., m|uch care|
|00000680| 20 69 73 20 6e 65 65 64 | 65 64 20 74 6f 20 64 65 | is need|ed to de|
|00000690| 73 63 72 69 62 65 20 69 | 6e 74 65 72 66 61 63 65 |scribe i|nterface|
|000006a0| 73 20 65 78 61 63 74 6c | 79 20 61 6e 64 20 74 6f |s exactl|y and to|
|000006b0| 0a 69 6d 70 6c 65 6d 65 | 6e 74 20 74 68 65 6d 20 |.impleme|nt them |
|000006c0| 69 6e 20 73 75 63 68 20 | 61 20 77 61 79 20 74 68 |in such |a way th|
|000006d0| 61 74 20 74 68 65 79 20 | 63 6f 6e 74 69 6e 75 65 |at they |continue|
|000006e0| 20 74 6f 20 77 6f 72 6b | 20 77 68 65 6e 20 61 20 | to work| when a |
|000006f0| 63 6c 69 65 6e 74 0a 6f | 72 20 73 65 72 76 65 72 |client.o|r server|
|00000700| 20 69 73 20 6d 6f 76 65 | 64 20 74 6f 20 61 20 64 | is move|d to a d|
|00000710| 69 66 66 65 72 65 6e 74 | 20 6d 61 63 68 69 6e 65 |ifferent| machine|
|00000720| 2e 20 20 53 69 6e 63 65 | 20 6d 61 63 68 69 6e 65 |. Since| machine|
|00000730| 73 20 6d 61 79 20 66 61 | 69 6c 0a 69 6e 64 65 70 |s may fa|il.indep|
|00000740| 65 6e 64 65 6e 74 6c 79 | 2c 20 65 72 72 6f 72 20 |endently|, error |
|00000750| 68 61 6e 64 6c 69 6e 67 | 20 6d 75 73 74 20 61 6c |handling| must al|
|00000760| 73 6f 20 62 65 20 74 72 | 65 61 74 65 64 20 6d 6f |so be tr|eated mo|
|00000770| 72 65 20 63 61 72 65 66 | 75 6c 6c 79 2e 0a 0a 41 |re caref|ully...A|
|00000780| 20 63 6f 6d 6d 6f 6e 20 | 61 70 70 72 6f 61 63 68 | common |approach|
|00000790| 20 74 6f 20 73 75 63 68 | 20 70 72 6f 62 6c 65 6d | to such| problem|
|000007a0| 73 20 69 73 20 74 6f 20 | 75 73 65 20 61 20 7b 5c |s is to |use a {\|
|000007b0| 65 6d 20 73 74 75 62 20 | 67 65 6e 65 72 61 74 6f |em stub |generato|
|000007c0| 72 7d 2e 0a 54 68 69 73 | 20 69 73 20 61 20 70 72 |r}..This| is a pr|
|000007d0| 6f 67 72 61 6d 20 74 68 | 61 74 20 74 61 6b 65 73 |ogram th|at takes|
|000007e0| 20 61 6e 20 69 6e 74 65 | 72 66 61 63 65 20 64 65 | an inte|rface de|
|000007f0| 73 63 72 69 70 74 69 6f | 6e 20 61 6e 64 20 74 72 |scriptio|n and tr|
|00000800| 61 6e 73 66 6f 72 6d 73 | 0a 69 74 20 69 6e 74 6f |ansforms|.it into|
|00000810| 20 66 75 6e 63 74 69 6f | 6e 73 20 74 68 61 74 20 | functio|ns that |
|00000820| 6d 75 73 74 20 62 65 20 | 63 6f 6d 70 69 6c 65 64 |must be |compiled|
|00000830| 20 61 6e 64 20 6c 69 6e | 6b 65 64 20 77 69 74 68 | and lin|ked with|
|00000840| 20 63 6c 69 65 6e 74 20 | 61 6e 64 0a 73 65 72 76 | client |and.serv|
|00000850| 65 72 20 61 70 70 6c 69 | 63 61 74 69 6f 6e 73 2e |er appli|cations.|
|00000860| 20 20 54 68 65 73 65 20 | 66 75 6e 63 74 69 6f 6e | These |function|
|00000870| 73 20 61 72 65 20 63 61 | 6c 6c 65 64 20 62 79 20 |s are ca|lled by |
|00000880| 74 68 65 20 61 70 70 6c | 69 63 61 74 69 6f 6e 0a |the appl|ication.|
|00000890| 63 6f 64 65 20 74 6f 20 | 74 61 6b 65 20 63 61 72 |code to |take car|
|000008a0| 65 20 6f 66 20 64 65 74 | 61 69 6c 73 20 6f 66 20 |e of det|ails of |
|000008b0| 69 6e 74 65 72 66 61 63 | 69 6e 67 20 74 6f 20 74 |interfac|ing to t|
|000008c0| 68 65 20 73 79 73 74 65 | 6d 27 73 20 52 50 43 20 |he syste|m's RPC |
|000008d0| 6c 61 79 65 72 2c 0a 74 | 6f 20 69 6d 70 6c 65 6d |layer,.t|o implem|
|000008e0| 65 6e 74 20 74 72 61 6e | 73 66 6f 72 6d 61 74 69 |ent tran|sformati|
|000008f0| 6f 6e 73 20 62 65 74 77 | 65 65 6e 20 64 61 74 61 |ons betw|een data|
|00000900| 20 72 65 70 72 65 73 65 | 6e 74 61 74 69 6f 6e 73 | represe|ntations|
|00000910| 20 6f 66 20 64 69 66 66 | 65 72 65 6e 74 0a 6d 61 | of diff|erent.ma|
|00000920| 63 68 69 6e 65 73 2c 20 | 74 6f 20 63 68 65 63 6b |chines, |to check|
|00000930| 20 66 6f 72 20 65 72 72 | 6f 72 73 2c 20 65 74 63 | for err|ors, etc|
|00000940| 2e 20 20 54 68 65 79 20 | 61 72 65 20 63 61 6c 6c |. They |are call|
|00000950| 65 64 20 60 73 74 75 62 | 73 27 20 62 65 63 61 75 |ed `stub|s' becau|
|00000960| 73 65 0a 74 68 65 79 20 | 64 6f 6e 27 74 20 61 63 |se.they |don't ac|
|00000970| 74 75 61 6c 6c 79 20 70 | 65 72 66 6f 72 6d 20 74 |tually p|erform t|
|00000980| 68 65 20 61 63 74 69 6f | 6e 20 74 68 61 74 20 74 |he actio|n that t|
|00000990| 68 65 79 20 61 72 65 20 | 63 61 6c 6c 65 64 20 66 |hey are |called f|
|000009a0| 6f 72 20 62 75 74 0a 6f | 6e 6c 79 20 72 65 6c 61 |or but.o|nly rela|
|000009b0| 79 20 74 68 65 20 70 61 | 72 61 6d 65 74 65 72 73 |y the pa|rameters|
|000009c0| 20 74 6f 20 74 68 65 20 | 73 65 72 76 65 72 0a 5c | to the |server.\|
|000009d0| 63 69 74 65 7b 52 50 43 | 7d 2e 0a 0a 41 6d 6f 65 |cite{RPC|}...Amoe|
|000009e0| 62 61 27 73 20 73 74 75 | 62 20 67 65 6e 65 72 61 |ba's stu|b genera|
|000009f0| 74 6f 72 20 69 73 20 63 | 61 6c 6c 65 64 20 41 49 |tor is c|alled AI|
|00000a00| 4c 2c 20 77 68 69 63 68 | 20 73 74 61 6e 64 73 20 |L, which| stands |
|00000a10| 66 6f 72 20 41 6d 6f 65 | 62 61 0a 49 6e 74 65 72 |for Amoe|ba.Inter|
|00000a20| 66 61 63 65 20 4c 61 6e | 67 75 61 67 65 0a 5c 63 |face Lan|guage.\c|
|00000a30| 69 74 65 7b 41 49 4c 7d | 2e 0a 54 68 65 20 66 69 |ite{AIL}|..The fi|
|00000a40| 72 73 74 20 76 65 72 73 | 69 6f 6e 20 6f 66 20 41 |rst vers|ion of A|
|00000a50| 49 4c 20 67 65 6e 65 72 | 61 74 65 64 20 6f 6e 6c |IL gener|ated onl|
|00000a60| 79 20 43 20 66 75 6e 63 | 74 69 6f 6e 73 2c 20 62 |y C func|tions, b|
|00000a70| 75 74 20 61 6e 20 65 78 | 70 6c 69 63 69 74 0a 67 |ut an ex|plicit.g|
|00000a80| 6f 61 6c 20 6f 66 20 41 | 49 4c 27 73 20 64 65 73 |oal of A|IL's des|
|00000a90| 69 67 6e 20 77 61 73 20 | 7b 5c 65 6d 20 72 65 74 |ign was |{\em ret|
|00000aa0| 61 72 67 65 74 61 62 69 | 6c 69 74 79 7d 3a 20 69 |argetabi|lity}: i|
|00000ab0| 74 20 73 68 6f 75 6c 64 | 20 62 65 20 70 6f 73 73 |t should| be poss|
|00000ac0| 69 62 6c 65 0a 74 6f 20 | 61 64 64 20 62 61 63 6b |ible.to |add back|
|00000ad0| 2d 65 6e 64 73 20 74 68 | 61 74 20 67 65 6e 65 72 |-ends th|at gener|
|00000ae0| 61 74 65 20 73 74 75 62 | 73 20 66 6f 72 20 64 69 |ate stub|s for di|
|00000af0| 66 66 65 72 65 6e 74 20 | 6c 61 6e 67 75 61 67 65 |fferent |language|
|00000b00| 73 20 66 72 6f 6d 20 74 | 68 65 0a 73 61 6d 65 20 |s from t|he.same |
|00000b10| 69 6e 74 65 72 66 61 63 | 65 20 64 65 73 63 72 69 |interfac|e descri|
|00000b20| 70 74 69 6f 6e 73 2e 20 | 20 4d 6f 72 65 6f 76 65 |ptions. | Moreove|
|00000b30| 72 2c 20 74 68 65 20 73 | 74 75 62 73 20 67 65 6e |r, the s|tubs gen|
|00000b40| 65 72 61 74 65 64 20 62 | 79 0a 64 69 66 66 65 72 |erated b|y.differ|
|00000b50| 65 6e 74 20 62 61 63 6b | 2d 65 6e 64 73 20 6d 75 |ent back|-ends mu|
|00000b60| 73 74 20 62 65 20 7b 5c | 65 6d 20 69 6e 74 65 72 |st be {\|em inter|
|00000b70| 6f 70 65 72 61 62 6c 65 | 7d 3a 20 61 20 63 6c 69 |operable|}: a cli|
|00000b80| 65 6e 74 20 77 72 69 74 | 74 65 6e 20 69 6e 0a 4d |ent writ|ten in.M|
|00000b90| 6f 64 75 6c 61 2d 33 2c | 20 73 61 79 2c 20 73 68 |odula-3,| say, sh|
|00000ba0| 6f 75 6c 64 20 62 65 20 | 61 62 6c 65 20 74 6f 20 |ould be |able to |
|00000bb0| 75 73 65 20 61 20 73 65 | 72 76 65 72 20 77 72 69 |use a se|rver wri|
|00000bc0| 74 74 65 6e 20 69 6e 20 | 43 2c 20 61 6e 64 20 76 |tten in |C, and v|
|00000bd0| 69 63 65 0a 76 65 72 73 | 61 2e 0a 0a 54 68 69 73 |ice.vers|a...This|
|00000be0| 20 69 6e 74 65 72 6f 70 | 65 72 61 62 69 6c 69 74 | interop|erabilit|
|00000bf0| 79 20 69 73 20 74 68 65 | 20 6b 65 79 20 74 6f 20 |y is the| key to |
|00000c00| 74 68 65 20 73 75 63 63 | 65 73 73 20 6f 66 20 74 |the succ|ess of t|
|00000c10| 68 65 20 6d 61 72 72 69 | 61 67 65 0a 62 65 74 77 |he marri|age.betw|
|00000c20| 65 65 6e 20 41 49 4c 20 | 61 6e 64 20 50 79 74 68 |een AIL |and Pyth|
|00000c30| 6f 6e 2e 20 20 50 79 74 | 68 6f 6e 20 69 73 20 61 |on. Pyt|hon is a|
|00000c40| 20 76 65 72 73 61 74 69 | 6c 65 20 69 6e 74 65 72 | versati|le inter|
|00000c50| 70 72 65 74 65 64 20 6c | 61 6e 67 75 61 67 65 0a |preted l|anguage.|
|00000c60| 64 65 76 65 6c 6f 70 65 | 64 20 62 79 20 74 68 65 |develope|d by the|
|00000c70| 20 66 69 72 73 74 20 61 | 75 74 68 6f 72 2e 20 20 | first a|uthor. |
|00000c80| 4f 72 69 67 69 6e 61 6c | 6c 79 20 69 6e 74 65 6e |Original|ly inten|
|00000c90| 64 65 64 20 61 73 20 61 | 6e 20 61 6c 74 65 72 6e |ded as a|n altern|
|00000ca0| 61 74 69 76 65 0a 66 6f | 72 20 74 68 65 20 6b 69 |ative.fo|r the ki|
|00000cb0| 6e 64 20 6f 66 20 6f 64 | 64 20 6a 6f 62 73 20 74 |nd of od|d jobs t|
|00000cc0| 68 61 74 20 61 72 65 20 | 74 72 61 64 69 74 69 6f |hat are |traditio|
|00000cd0| 6e 61 6c 6c 79 20 73 6f | 6c 76 65 64 20 62 79 20 |nally so|lved by |
|00000ce0| 61 20 6d 69 78 74 75 72 | 65 20 6f 66 0a 73 68 65 |a mixtur|e of.she|
|00000cf0| 6c 6c 20 73 63 72 69 70 | 74 73 2c 20 6d 61 6e 75 |ll scrip|ts, manu|
|00000d00| 61 6c 6c 79 20 67 69 76 | 65 6e 20 73 68 65 6c 6c |ally giv|en shell|
|00000d10| 20 63 6f 6d 6d 61 6e 64 | 73 2c 20 61 6e 64 20 61 | command|s, and a|
|00000d20| 6e 20 6f 63 63 61 73 69 | 6f 6e 61 6c 20 61 64 20 |n occasi|onal ad |
|00000d30| 68 6f 63 0a 43 20 70 72 | 6f 67 72 61 6d 2c 20 50 |hoc.C pr|ogram, P|
|00000d40| 79 74 68 6f 6e 20 68 61 | 73 20 65 76 6f 6c 76 65 |ython ha|s evolve|
|00000d50| 64 20 69 6e 74 6f 20 61 | 20 67 65 6e 65 72 61 6c |d into a| general|
|00000d60| 20 69 6e 74 65 72 61 63 | 74 69 76 65 20 70 72 6f | interac|tive pro|
|00000d70| 74 6f 74 79 70 69 6e 67 | 0a 6c 61 6e 67 75 61 67 |totyping|.languag|
|00000d80| 65 2e 20 20 49 74 20 68 | 61 73 20 62 65 65 6e 20 |e. It h|as been |
|00000d90| 61 70 70 6c 69 65 64 20 | 74 6f 20 61 20 77 69 64 |applied |to a wid|
|00000da0| 65 20 72 61 6e 67 65 20 | 6f 66 20 70 72 6f 62 6c |e range |of probl|
|00000db0| 65 6d 73 2c 20 66 72 6f | 6d 0a 72 65 70 6c 61 63 |ems, fro|m.replac|
|00000dc0| 65 6d 65 6e 74 73 20 66 | 6f 72 20 6c 61 72 67 65 |ements f|or large|
|00000dd0| 20 73 68 65 6c 6c 20 73 | 63 72 69 70 74 73 20 74 | shell s|cripts t|
|00000de0| 6f 20 66 61 6e 63 79 20 | 67 72 61 70 68 69 63 73 |o fancy |graphics|
|00000df0| 20 64 65 6d 6f 73 20 61 | 6e 64 0a 6d 75 6c 74 69 | demos a|nd.multi|
|00000e00| 6d 65 64 69 61 20 61 70 | 70 6c 69 63 61 74 69 6f |media ap|plicatio|
|00000e10| 6e 73 2e 0a 0a 4f 6e 65 | 20 6f 66 20 50 79 74 68 |ns...One| of Pyth|
|00000e20| 6f 6e 27 73 20 73 74 72 | 65 6e 67 74 68 73 20 69 |on's str|engths i|
|00000e30| 73 20 74 68 65 20 61 62 | 69 6c 69 74 79 20 66 6f |s the ab|ility fo|
|00000e40| 72 20 74 68 65 20 75 73 | 65 72 20 74 6f 20 74 79 |r the us|er to ty|
|00000e50| 70 65 20 69 6e 20 73 6f | 6d 65 0a 63 6f 64 65 20 |pe in so|me.code |
|00000e60| 61 6e 64 20 69 6d 6d 65 | 64 69 61 74 65 6c 79 20 |and imme|diately |
|00000e70| 72 75 6e 20 69 74 3a 20 | 6e 6f 20 63 6f 6d 70 69 |run it: |no compi|
|00000e80| 6c 61 74 69 6f 6e 20 6f | 72 20 6c 69 6e 6b 69 6e |lation o|r linkin|
|00000e90| 67 20 69 73 20 6e 65 63 | 65 73 73 61 72 79 2e 0a |g is nec|essary..|
|00000ea0| 49 6e 74 65 72 61 63 74 | 69 76 65 20 70 65 72 66 |Interact|ive perf|
|00000eb0| 6f 72 6d 61 6e 63 65 20 | 69 73 20 66 75 72 74 68 |ormance |is furth|
|00000ec0| 65 72 20 65 6e 68 61 6e | 63 65 64 20 62 79 20 50 |er enhan|ced by P|
|00000ed0| 79 74 68 6f 6e 27 73 20 | 63 6f 6e 63 69 73 65 2c |ython's |concise,|
|00000ee0| 20 63 6c 65 61 72 0a 73 | 79 6e 74 61 78 2c 20 69 | clear.s|yntax, i|
|00000ef0| 74 73 20 76 65 72 79 2d | 68 69 67 68 2d 6c 65 76 |ts very-|high-lev|
|00000f00| 65 6c 20 64 61 74 61 20 | 74 79 70 65 73 2c 20 61 |el data |types, a|
|00000f10| 6e 64 20 69 74 73 20 6c | 61 63 6b 20 6f 66 20 64 |nd its l|ack of d|
|00000f20| 65 63 6c 61 72 61 74 69 | 6f 6e 73 0a 28 77 68 69 |eclarati|ons.(whi|
|00000f30| 63 68 20 69 73 20 63 6f | 6d 70 65 6e 73 61 74 65 |ch is co|mpensate|
|00000f40| 64 20 62 79 20 72 75 6e | 2d 74 69 6d 65 20 74 79 |d by run|-time ty|
|00000f50| 70 65 20 63 68 65 63 6b | 69 6e 67 29 2e 20 20 41 |pe check|ing). A|
|00000f60| 6c 6c 20 74 68 69 73 20 | 6d 61 6b 65 73 0a 70 72 |ll this |makes.pr|
|00000f70| 6f 67 72 61 6d 6d 69 6e | 67 20 69 6e 20 50 79 74 |ogrammin|g in Pyt|
|00000f80| 68 6f 6e 20 66 65 65 6c | 20 6c 69 6b 65 20 61 20 |hon feel| like a |
|00000f90| 6c 65 69 73 75 72 65 20 | 74 72 69 70 20 63 6f 6d |leisure |trip com|
|00000fa0| 70 61 72 65 64 20 74 6f | 20 74 68 65 20 68 61 72 |pared to| the har|
|00000fb0| 64 0a 77 6f 72 6b 20 69 | 6e 76 6f 6c 76 65 64 20 |d.work i|nvolved |
|00000fc0| 69 6e 20 77 72 69 74 69 | 6e 67 20 61 6e 64 20 64 |in writi|ng and d|
|00000fd0| 65 62 75 67 67 69 6e 67 | 20 65 76 65 6e 20 61 20 |ebugging| even a |
|00000fe0| 73 6d 61 6c 6c 69 73 68 | 20 43 20 70 72 6f 67 72 |smallish| C progr|
|00000ff0| 61 6d 2e 0a 0a 49 74 20 | 73 68 6f 75 6c 64 20 62 |am...It |should b|
|00001000| 65 20 63 6c 65 61 72 20 | 62 79 20 6e 6f 77 20 74 |e clear |by now t|
|00001010| 68 61 74 20 50 79 74 68 | 6f 6e 20 77 69 6c 6c 20 |hat Pyth|on will |
|00001020| 62 65 20 74 68 65 20 69 | 64 65 61 6c 20 74 6f 6f |be the i|deal too|
|00001030| 6c 20 74 6f 20 74 65 73 | 74 0a 73 65 72 76 65 72 |l to tes|t.server|
|00001040| 73 20 61 6e 64 20 74 68 | 65 69 72 20 69 6e 74 65 |s and th|eir inte|
|00001050| 72 66 61 63 65 73 2e 20 | 20 45 73 70 65 63 69 61 |rfaces. | Especia|
|00001060| 6c 6c 79 20 64 75 72 69 | 6e 67 20 74 68 65 20 64 |lly duri|ng the d|
|00001070| 65 76 65 6c 6f 70 6d 65 | 6e 74 20 6f 66 20 61 0a |evelopme|nt of a.|
|00001080| 63 6f 6d 70 6c 65 78 20 | 73 65 72 76 65 72 2c 20 |complex |server, |
|00001090| 6f 6e 65 20 6f 66 74 65 | 6e 20 6e 65 65 64 73 20 |one ofte|n needs |
|000010a0| 74 6f 20 67 65 6e 65 72 | 61 74 65 20 74 65 73 74 |to gener|ate test|
|000010b0| 20 72 65 71 75 65 73 74 | 73 20 6f 6e 20 61 6e 20 | request|s on an |
|000010c0| 61 64 20 68 6f 63 0a 62 | 61 73 69 73 2c 20 74 6f |ad hoc.b|asis, to|
|000010d0| 20 61 6e 73 77 65 72 20 | 71 75 65 73 74 69 6f 6e | answer |question|
|000010e0| 73 20 6c 69 6b 65 20 60 | 60 77 68 61 74 20 68 61 |s like `|`what ha|
|000010f0| 70 70 65 6e 73 20 69 66 | 20 72 65 71 75 65 73 74 |ppens if| request|
|00001100| 20 58 20 61 72 72 69 76 | 65 73 0a 77 68 65 6e 20 | X arriv|es.when |
|00001110| 74 68 65 20 73 65 72 76 | 65 72 20 69 73 20 69 6e |the serv|er is in|
|00001120| 20 73 74 61 74 65 20 59 | 2c 27 27 20 74 6f 20 74 | state Y|,'' to t|
|00001130| 65 73 74 20 74 68 65 20 | 62 65 68 61 76 69 6f 72 |est the |behavior|
|00001140| 20 6f 66 20 74 68 65 20 | 73 65 72 76 65 72 0a 77 | of the |server.w|
|00001150| 69 74 68 20 72 65 71 75 | 65 73 74 73 20 74 68 61 |ith requ|ests tha|
|00001160| 74 20 74 6f 75 63 68 20 | 69 74 73 20 6c 69 6d 69 |t touch |its limi|
|00001170| 74 61 74 69 6f 6e 73 2c | 20 74 6f 20 63 68 65 63 |tations,| to chec|
|00001180| 6b 20 73 65 72 76 65 72 | 20 72 65 73 70 6f 6e 73 |k server| respons|
|00001190| 65 73 20 74 6f 0a 61 6c | 6c 20 73 6f 72 74 73 20 |es to.al|l sorts |
|000011a0| 6f 66 20 77 72 6f 6e 67 | 20 72 65 71 75 65 73 74 |of wrong| request|
|000011b0| 73 2c 20 65 74 63 2e 20 | 20 50 79 74 68 6f 6e 27 |s, etc. | Python'|
|000011c0| 73 20 61 62 69 6c 69 74 | 79 20 74 6f 20 69 6d 6d |s abilit|y to imm|
|000011d0| 65 64 69 61 74 65 6c 79 | 0a 65 78 65 63 75 74 65 |ediately|.execute|
|000011e0| 20 60 69 6d 70 72 6f 76 | 69 73 65 64 27 20 63 6f | `improv|ised' co|
|000011f0| 64 65 20 6d 61 6b 65 73 | 20 69 74 20 61 20 6d 75 |de makes| it a mu|
|00001200| 63 68 20 62 65 74 74 65 | 72 20 74 6f 6f 6c 20 66 |ch bette|r tool f|
|00001210| 6f 72 20 74 68 69 73 0a | 73 69 74 75 61 74 69 6f |or this.|situatio|
|00001220| 6e 20 74 68 61 6e 20 43 | 2e 0a 0a 54 68 65 20 6c |n than C|...The l|
|00001230| 69 6e 6b 20 74 6f 20 41 | 49 4c 20 65 78 74 65 6e |ink to A|IL exten|
|00001240| 64 73 20 50 79 74 68 6f | 6e 20 77 69 74 68 20 74 |ds Pytho|n with t|
|00001250| 68 65 20 6e 65 63 65 73 | 73 61 72 79 20 66 75 6e |he neces|sary fun|
|00001260| 63 74 69 6f 6e 61 6c 69 | 74 79 20 74 6f 0a 63 6f |ctionali|ty to.co|
|00001270| 6e 6e 65 63 74 20 74 6f | 20 61 72 62 69 74 72 61 |nnect to| arbitra|
|00001280| 72 79 20 73 65 72 76 65 | 72 73 2c 20 6d 61 6b 69 |ry serve|rs, maki|
|00001290| 6e 67 20 74 68 65 20 73 | 65 72 76 65 72 20 74 65 |ng the s|erver te|
|000012a0| 73 74 62 65 64 20 73 6b | 65 74 63 68 65 64 20 61 |stbed sk|etched a|
|000012b0| 62 6f 76 65 0a 61 20 72 | 65 61 6c 69 74 79 2e 20 |bove.a r|eality. |
|000012c0| 20 50 79 74 68 6f 6e 27 | 73 20 68 69 67 68 2d 6c | Python'|s high-l|
|000012d0| 65 76 65 6c 20 64 61 74 | 61 20 74 79 70 65 73 2c |evel dat|a types,|
|000012e0| 20 67 65 6e 65 72 61 6c | 20 70 72 6f 67 72 61 6d | general| program|
|000012f0| 6d 69 6e 67 0a 66 65 61 | 74 75 72 65 73 2c 20 61 |ming.fea|tures, a|
|00001300| 6e 64 20 73 79 73 74 65 | 6d 20 69 6e 74 65 72 66 |nd syste|m interf|
|00001310| 61 63 65 20 65 6e 73 75 | 72 65 20 74 68 61 74 20 |ace ensu|re that |
|00001320| 69 74 20 68 61 73 20 61 | 6c 6c 20 74 68 65 20 70 |it has a|ll the p|
|00001330| 6f 77 65 72 20 61 6e 64 | 0a 66 6c 65 78 69 62 69 |ower and|.flexibi|
|00001340| 6c 69 74 79 20 6e 65 65 | 64 65 64 20 66 6f 72 20 |lity nee|ded for |
|00001350| 74 68 65 20 6a 6f 62 2e | 0a 0a 4f 6e 65 20 63 6f |the job.|..One co|
|00001360| 75 6c 64 20 67 6f 20 65 | 76 65 6e 20 66 75 72 74 |uld go e|ven furt|
|00001370| 68 65 72 20 74 68 61 6e | 20 74 68 69 73 2e 20 20 |her than| this. |
|00001380| 43 75 72 72 65 6e 74 20 | 64 69 73 74 72 69 62 75 |Current |distribu|
|00001390| 74 65 64 20 6f 70 65 72 | 61 74 69 6e 67 0a 73 79 |ted oper|ating.sy|
|000013a0| 73 74 65 6d 73 2c 20 62 | 61 73 65 64 20 6f 6e 20 |stems, b|ased on |
|000013b0| 63 6c 69 65 6e 74 2d 73 | 65 72 76 65 72 20 69 6e |client-s|erver in|
|000013c0| 74 65 72 61 63 74 69 6f | 6e 2c 20 61 6c 6c 20 6c |teractio|n, all l|
|000013d0| 61 63 6b 20 61 20 67 6f | 6f 64 20 63 6f 6d 6d 61 |ack a go|od comma|
|000013e0| 6e 64 0a 6c 61 6e 67 75 | 61 67 65 20 6f 72 20 60 |nd.langu|age or `|
|000013f0| 73 68 65 6c 6c 27 20 74 | 6f 20 67 69 76 65 20 61 |shell' t|o give a|
|00001400| 64 65 71 75 61 74 65 20 | 61 63 63 65 73 73 20 74 |dequate |access t|
|00001410| 6f 20 61 76 61 69 6c 61 | 62 6c 65 20 73 65 72 76 |o availa|ble serv|
|00001420| 69 63 65 73 2e 0a 50 79 | 74 68 6f 6e 20 68 61 73 |ices..Py|thon has|
|00001430| 20 63 6f 6e 73 69 64 65 | 72 61 62 6c 65 20 70 6f | conside|rable po|
|00001440| 74 65 6e 74 69 61 6c 20 | 66 6f 72 20 62 65 63 6f |tential |for beco|
|00001450| 6d 69 6e 67 20 73 75 63 | 68 20 61 20 73 68 65 6c |ming suc|h a shel|
|00001460| 6c 2e 0a 0a 5c 73 75 62 | 73 65 63 74 69 6f 6e 7b |l...\sub|section{|
|00001470| 4f 76 65 72 76 69 65 77 | 20 6f 66 20 74 68 69 73 |Overview| of this|
|00001480| 20 50 61 70 65 72 7d 0a | 0a 54 68 65 20 72 65 73 | Paper}.|.The res|
|00001490| 74 20 6f 66 20 74 68 69 | 73 20 70 61 70 65 72 20 |t of thi|s paper |
|000014a0| 63 6f 6e 74 61 69 6e 73 | 20 74 68 72 65 65 20 6d |contains| three m|
|000014b0| 61 6a 6f 72 20 73 65 63 | 74 69 6f 6e 73 20 61 6e |ajor sec|tions an|
|000014c0| 64 20 61 20 63 6f 6e 63 | 6c 75 73 69 6f 6e 2e 0a |d a conc|lusion..|
|000014d0| 46 69 72 73 74 20 61 6e | 20 6f 76 65 72 76 69 65 |First an| overvie|
|000014e0| 77 20 6f 66 20 74 68 65 | 20 50 79 74 68 6f 6e 20 |w of the| Python |
|000014f0| 70 72 6f 67 72 61 6d 6d | 69 6e 67 20 6c 61 6e 67 |programm|ing lang|
|00001500| 75 61 67 65 20 69 73 20 | 67 69 76 65 6e 2e 20 20 |uage is |given. |
|00001510| 4e 65 78 74 0a 63 6f 6d | 65 73 20 61 20 73 68 6f |Next.com|es a sho|
|00001520| 72 74 20 64 65 73 63 72 | 69 70 74 69 6f 6e 20 6f |rt descr|iption o|
|00001530| 66 20 41 49 4c 2c 20 74 | 6f 67 65 74 68 65 72 20 |f AIL, t|ogether |
|00001540| 77 69 74 68 20 73 6f 6d | 65 20 72 65 6c 65 76 61 |with som|e releva|
|00001550| 6e 74 20 64 65 74 61 69 | 6c 73 0a 61 62 6f 75 74 |nt detai|ls.about|
|00001560| 20 41 6d 6f 65 62 61 2e | 20 20 46 69 6e 61 6c 6c | Amoeba.| Finall|
|00001570| 79 2c 20 74 68 65 20 64 | 65 73 69 67 6e 20 61 6e |y, the d|esign an|
|00001580| 64 20 63 6f 6e 73 74 72 | 75 63 74 69 6f 6e 20 6f |d constr|uction o|
|00001590| 66 20 74 68 65 20 6c 69 | 6e 6b 0a 62 65 74 77 65 |f the li|nk.betwe|
|000015a0| 65 6e 20 50 79 74 68 6f | 6e 20 61 6e 64 20 41 49 |en Pytho|n and AI|
|000015b0| 4c 20 69 73 20 64 65 73 | 63 72 69 62 65 64 20 69 |L is des|cribed i|
|000015c0| 6e 20 6d 75 63 68 20 64 | 65 74 61 69 6c 2e 20 20 |n much d|etail. |
|000015d0| 54 68 65 20 63 6f 6e 63 | 6c 75 73 69 6f 6e 0a 6c |The conc|lusion.l|
|000015e0| 6f 6f 6b 73 20 62 61 63 | 6b 20 61 74 20 74 68 65 |ooks bac|k at the|
|000015f0| 20 77 6f 72 6b 20 61 6e | 64 20 70 6f 69 6e 74 73 | work an|d points|
|00001600| 20 6f 75 74 20 77 65 61 | 6b 6e 65 73 73 65 73 20 | out wea|knesses |
|00001610| 61 6e 64 20 73 74 72 65 | 6e 67 74 68 73 20 6f 66 |and stre|ngths of|
|00001620| 0a 50 79 74 68 6f 6e 20 | 61 6e 64 20 41 49 4c 20 |.Python |and AIL |
|00001630| 74 68 61 74 20 77 65 72 | 65 20 64 69 73 63 6f 76 |that wer|e discov|
|00001640| 65 72 65 64 20 69 6e 20 | 74 68 65 20 70 72 6f 63 |ered in |the proc|
|00001650| 65 73 73 2e 0a 0a 5c 73 | 65 63 74 69 6f 6e 7b 41 |ess...\s|ection{A|
|00001660| 6e 20 4f 76 65 72 76 69 | 65 77 20 6f 66 20 50 79 |n Overvi|ew of Py|
|00001670| 74 68 6f 6e 7d 0a 0a 50 | 79 74 68 6f 6e 25 0a 5c |thon}..P|ython%.\|
|00001680| 66 6f 6f 74 6e 6f 74 65 | 7b 0a 4e 61 6d 65 64 20 |footnote|{.Named |
|00001690| 61 66 74 65 72 20 74 68 | 65 20 66 75 6e 6e 79 20 |after th|e funny |
|000016a0| 54 56 20 73 68 6f 77 2c | 20 6e 6f 74 20 74 68 65 |TV show,| not the|
|000016b0| 20 6e 61 73 74 79 20 72 | 65 70 74 69 6c 65 2e 0a | nasty r|eptile..|
|000016c0| 7d 0a 6f 77 65 73 20 6d | 75 63 68 20 74 6f 20 41 |}.owes m|uch to A|
|000016d0| 42 43 0a 5c 63 69 74 65 | 7b 41 42 43 7d 2c 0a 61 |BC.\cite|{ABC},.a|
|000016e0| 20 6c 61 6e 67 75 61 67 | 65 20 64 65 76 65 6c 6f | languag|e develo|
|000016f0| 70 65 64 20 61 74 20 43 | 57 49 20 61 73 20 61 20 |ped at C|WI as a |
|00001700| 70 72 6f 67 72 61 6d 6d | 69 6e 67 20 6c 61 6e 67 |programm|ing lang|
|00001710| 75 61 67 65 20 66 6f 72 | 20 6e 6f 6e 2d 65 78 70 |uage for| non-exp|
|00001720| 65 72 74 0a 63 6f 6d 70 | 75 74 65 72 20 75 73 65 |ert.comp|uter use|
|00001730| 72 73 2e 20 20 50 79 74 | 68 6f 6e 20 62 6f 72 72 |rs. Pyt|hon borr|
|00001740| 6f 77 73 20 66 72 65 65 | 6c 79 20 66 72 6f 6d 20 |ows free|ly from |
|00001750| 41 42 43 27 73 20 73 79 | 6e 74 61 78 20 61 6e 64 |ABC's sy|ntax and|
|00001760| 20 64 61 74 61 0a 74 79 | 70 65 73 2c 20 62 75 74 | data.ty|pes, but|
|00001770| 20 61 64 64 73 20 6d 6f | 64 75 6c 65 73 2c 20 65 | adds mo|dules, e|
|00001780| 78 63 65 70 74 69 6f 6e | 73 20 61 6e 64 20 63 6c |xception|s and cl|
|00001790| 61 73 73 65 73 2c 20 65 | 78 74 65 6e 73 69 62 69 |asses, e|xtensibi|
|000017a0| 6c 69 74 79 2c 20 61 6e | 64 0a 74 68 65 20 61 62 |lity, an|d.the ab|
|000017b0| 69 6c 69 74 79 20 74 6f | 20 63 61 6c 6c 20 73 79 |ility to| call sy|
|000017c0| 73 74 65 6d 20 66 75 6e | 63 74 69 6f 6e 73 2e 20 |stem fun|ctions. |
|000017d0| 20 54 68 65 20 63 6f 6e | 63 65 70 74 73 20 6f 66 | The con|cepts of|
|000017e0| 20 6d 6f 64 75 6c 65 73 | 2c 0a 65 78 63 65 70 74 | modules|,.except|
|000017f0| 69 6f 6e 73 20 61 6e 64 | 20 28 74 6f 20 73 6f 6d |ions and| (to som|
|00001800| 65 20 65 78 74 65 6e 74 | 29 20 63 6c 61 73 73 65 |e extent|) classe|
|00001810| 73 20 61 72 65 20 69 6e | 66 6c 75 65 6e 63 65 64 |s are in|fluenced|
|00001820| 20 73 74 72 6f 6e 67 6c | 79 20 62 79 0a 74 68 65 | strongl|y by.the|
|00001830| 69 72 20 6f 63 63 75 72 | 72 65 6e 63 65 20 69 6e |ir occur|rence in|
|00001840| 20 4d 6f 64 75 6c 61 2d | 33 0a 5c 63 69 74 65 7b | Modula-|3.\cite{|
|00001850| 4d 6f 64 75 6c 61 2d 33 | 7d 2e 0a 0a 41 6c 74 68 |Modula-3|}...Alth|
|00001860| 6f 75 67 68 20 50 79 74 | 68 6f 6e 20 72 65 73 65 |ough Pyt|hon rese|
|00001870| 6d 62 6c 65 73 20 41 42 | 43 20 69 6e 20 6d 61 6e |mbles AB|C in man|
|00001880| 79 20 77 61 79 73 2c 20 | 74 68 65 72 65 20 69 73 |y ways, |there is|
|00001890| 20 61 20 61 20 63 6c 65 | 61 72 0a 64 69 66 66 65 | a a cle|ar.diffe|
|000018a0| 72 65 6e 63 65 20 69 6e | 20 61 70 70 6c 69 63 61 |rence in| applica|
|000018b0| 74 69 6f 6e 20 64 6f 6d | 61 69 6e 2e 20 20 41 42 |tion dom|ain. AB|
|000018c0| 43 20 69 73 20 69 6e 74 | 65 6e 64 65 64 20 74 6f |C is int|ended to|
|000018d0| 20 62 65 20 74 68 65 20 | 6f 6e 6c 79 0a 70 72 6f | be the |only.pro|
|000018e0| 67 72 61 6d 6d 69 6e 67 | 20 6c 61 6e 67 75 61 67 |gramming| languag|
|000018f0| 65 20 66 6f 72 20 74 68 | 6f 73 65 20 77 68 6f 20 |e for th|ose who |
|00001900| 75 73 65 20 61 20 63 6f | 6d 70 75 74 65 72 20 61 |use a co|mputer a|
|00001910| 73 20 61 20 74 6f 6f 6c | 2c 20 62 75 74 0a 6f 63 |s a tool|, but.oc|
|00001920| 63 61 73 69 6f 6e 61 6c | 6c 79 20 6e 65 65 64 20 |casional|ly need |
|00001930| 74 6f 20 77 72 69 74 65 | 20 61 20 70 72 6f 67 72 |to write| a progr|
|00001940| 61 6d 2e 20 20 46 6f 72 | 20 74 68 69 73 20 72 65 |am. For| this re|
|00001950| 61 73 6f 6e 2c 20 41 42 | 43 20 69 73 20 6e 6f 74 |ason, AB|C is not|
|00001960| 0a 6a 75 73 74 20 61 20 | 70 72 6f 67 72 61 6d 6d |.just a |programm|
|00001970| 69 6e 67 20 6c 61 6e 67 | 75 61 67 65 20 62 75 74 |ing lang|uage but|
|00001980| 20 61 6c 73 6f 20 61 20 | 70 72 6f 67 72 61 6d 6d | also a |programm|
|00001990| 69 6e 67 20 65 6e 76 69 | 72 6f 6e 6d 65 6e 74 2c |ing envi|ronment,|
|000019a0| 20 77 68 69 63 68 0a 63 | 6f 6d 65 73 20 77 69 74 | which.c|omes wit|
|000019b0| 68 20 61 6e 20 69 6e 74 | 65 67 72 61 74 65 64 20 |h an int|egrated |
|000019c0| 73 79 6e 74 61 78 2d 64 | 69 72 65 63 74 65 64 20 |syntax-d|irected |
|000019d0| 65 64 69 74 6f 72 20 61 | 6e 64 20 73 6f 6d 65 20 |editor a|nd some |
|000019e0| 73 6f 75 72 63 65 0a 6d | 61 6e 69 70 75 6c 61 74 |source.m|anipulat|
|000019f0| 69 6f 6e 20 63 6f 6d 6d | 61 6e 64 73 2e 20 20 50 |ion comm|ands. P|
|00001a00| 79 74 68 6f 6e 2c 20 6f | 6e 20 74 68 65 20 6f 74 |ython, o|n the ot|
|00001a10| 68 65 72 20 68 61 6e 64 | 2c 20 61 69 6d 73 20 74 |her hand|, aims t|
|00001a20| 6f 20 62 65 20 61 20 74 | 6f 6f 6c 0a 66 6f 72 20 |o be a t|ool.for |
|00001a30| 70 72 6f 66 65 73 73 69 | 6f 6e 61 6c 20 28 73 79 |professi|onal (sy|
|00001a40| 73 74 65 6d 29 20 70 72 | 6f 67 72 61 6d 6d 65 72 |stem) pr|ogrammer|
|00001a50| 73 2c 20 66 6f 72 20 77 | 68 6f 6d 20 68 61 76 69 |s, for w|hom havi|
|00001a60| 6e 67 20 61 20 63 68 6f | 69 63 65 20 6f 66 0a 6c |ng a cho|ice of.l|
|00001a70| 61 6e 67 75 61 67 65 73 | 20 77 69 74 68 20 64 69 |anguages| with di|
|00001a80| 66 66 65 72 65 6e 74 20 | 66 65 61 74 75 72 65 20 |fferent |feature |
|00001a90| 73 65 74 73 20 6d 61 6b | 65 73 20 69 74 20 70 6f |sets mak|es it po|
|00001aa0| 73 73 69 62 6c 65 20 74 | 6f 20 63 68 6f 6f 73 65 |ssible t|o choose|
|00001ab0| 20 60 74 68 65 0a 72 69 | 67 68 74 20 74 6f 6f 6c | `the.ri|ght tool|
|00001ac0| 20 66 6f 72 20 74 68 65 | 20 6a 6f 62 2e 27 20 20 | for the| job.' |
|00001ad0| 54 68 65 20 66 65 61 74 | 75 72 65 73 20 61 64 64 |The feat|ures add|
|00001ae0| 65 64 20 74 6f 20 50 79 | 74 68 6f 6e 20 6d 61 6b |ed to Py|thon mak|
|00001af0| 65 20 69 74 20 6d 6f 72 | 65 0a 75 73 65 66 75 6c |e it mor|e.useful|
|00001b00| 20 74 68 61 6e 20 41 42 | 43 20 69 6e 20 61 6e 20 | than AB|C in an |
|00001b10| 65 6e 76 69 72 6f 6e 6d | 65 6e 74 20 77 68 65 72 |environm|ent wher|
|00001b20| 65 20 61 63 63 65 73 73 | 20 74 6f 20 73 79 73 74 |e access| to syst|
|00001b30| 65 6d 20 66 75 6e 63 74 | 69 6f 6e 73 0a 28 73 75 |em funct|ions.(su|
|00001b40| 63 68 20 61 73 20 66 69 | 6c 65 20 61 6e 64 20 64 |ch as fi|le and d|
|00001b50| 69 72 65 63 74 6f 72 79 | 20 6d 61 6e 69 70 75 6c |irectory| manipul|
|00001b60| 61 74 69 6f 6e 73 29 20 | 61 72 65 20 63 6f 6d 6d |ations) |are comm|
|00001b70| 6f 6e 2e 20 20 54 68 65 | 79 20 61 6c 73 6f 0a 73 |on. The|y also.s|
|00001b80| 75 70 70 6f 72 74 20 74 | 68 65 20 62 75 69 6c 64 |upport t|he build|
|00001b90| 69 6e 67 20 6f 66 20 6c | 61 72 67 65 72 20 73 79 |ing of l|arger sy|
|00001ba0| 73 74 65 6d 73 20 61 6e | 64 20 6c 69 62 72 61 72 |stems an|d librar|
|00001bb0| 69 65 73 2e 20 20 54 68 | 65 20 50 79 74 68 6f 6e |ies. Th|e Python|
|00001bc0| 0a 69 6d 70 6c 65 6d 65 | 6e 74 61 74 69 6f 6e 20 |.impleme|ntation |
|00001bd0| 6f 66 66 65 72 73 20 6c | 69 74 74 6c 65 20 69 6e |offers l|ittle in|
|00001be0| 20 74 68 65 20 77 61 79 | 20 6f 66 20 61 20 70 72 | the way| of a pr|
|00001bf0| 6f 67 72 61 6d 6d 69 6e | 67 20 65 6e 76 69 72 6f |ogrammin|g enviro|
|00001c00| 6e 6d 65 6e 74 2c 0a 62 | 75 74 20 69 73 20 64 65 |nment,.b|ut is de|
|00001c10| 73 69 67 6e 65 64 20 74 | 6f 20 69 6e 74 65 67 72 |signed t|o integr|
|00001c20| 61 74 65 20 73 65 61 6d | 6c 65 73 73 6c 79 20 77 |ate seam|lessly w|
|00001c30| 69 74 68 20 65 78 69 73 | 74 69 6e 67 20 70 72 6f |ith exis|ting pro|
|00001c40| 67 72 61 6d 6d 69 6e 67 | 0a 65 6e 76 69 72 6f 6e |gramming|.environ|
|00001c50| 6d 65 6e 74 73 20 28 65 | 2e 67 2e 20 55 4e 49 58 |ments (e|.g. UNIX|
|00001c60| 20 61 6e 64 20 45 6d 61 | 63 73 29 2e 0a 0a 50 65 | and Ema|cs)...Pe|
|00001c70| 72 68 61 70 73 20 74 68 | 65 20 62 65 73 74 20 69 |rhaps th|e best i|
|00001c80| 6e 74 72 6f 64 75 63 74 | 69 6f 6e 20 74 6f 20 50 |ntroduct|ion to P|
|00001c90| 79 74 68 6f 6e 20 69 73 | 20 61 20 73 68 6f 72 74 |ython is| a short|
|00001ca0| 20 65 78 61 6d 70 6c 65 | 2e 20 20 54 68 65 0a 66 | example|. The.f|
|00001cb0| 6f 6c 6c 6f 77 69 6e 67 | 20 69 73 20 61 20 63 6f |ollowing| is a co|
|00001cc0| 6d 70 6c 65 74 65 20 50 | 79 74 68 6f 6e 20 70 72 |mplete P|ython pr|
|00001cd0| 6f 67 72 61 6d 20 74 6f | 20 6c 69 73 74 20 74 68 |ogram to| list th|
|00001ce0| 65 20 63 6f 6e 74 65 6e | 74 73 20 6f 66 20 61 20 |e conten|ts of a |
|00001cf0| 55 4e 49 58 0a 64 69 72 | 65 63 74 6f 72 79 2e 0a |UNIX.dir|ectory..|
|00001d00| 5c 62 65 67 69 6e 7b 76 | 65 72 62 61 74 69 6d 7d |\begin{v|erbatim}|
|00001d10| 0a 69 6d 70 6f 72 74 20 | 73 79 73 2c 20 70 6f 73 |.import |sys, pos|
|00001d20| 69 78 0a 0a 64 65 66 20 | 6c 73 28 64 69 72 6e 61 |ix..def |ls(dirna|
|00001d30| 6d 65 29 3a 20 20 20 20 | 23 20 50 72 69 6e 74 20 |me): |# Print |
|00001d40| 73 6f 72 74 65 64 20 64 | 69 72 65 63 74 6f 72 79 |sorted d|irectory|
|00001d50| 20 63 6f 6e 74 65 6e 74 | 73 0a 20 20 20 20 6e 61 | content|s. na|
|00001d60| 6d 65 73 20 3d 20 70 6f | 73 69 78 2e 6c 69 73 74 |mes = po|six.list|
|00001d70| 64 69 72 28 64 69 72 6e | 61 6d 65 29 0a 20 20 20 |dir(dirn|ame). |
|00001d80| 20 6e 61 6d 65 73 2e 73 | 6f 72 74 28 29 0a 20 20 | names.s|ort(). |
|00001d90| 20 20 66 6f 72 20 6e 61 | 6d 65 20 69 6e 20 6e 61 | for na|me in na|
|00001da0| 6d 65 73 3a 0a 20 20 20 | 20 20 20 20 20 69 66 20 |mes:. | if |
|00001db0| 6e 61 6d 65 5b 30 5d 20 | 21 3d 20 27 2e 27 3a 20 |name[0] |!= '.': |
|00001dc0| 70 72 69 6e 74 20 6e 61 | 6d 65 0a 0a 6c 73 28 73 |print na|me..ls(s|
|00001dd0| 79 73 2e 61 72 67 76 5b | 31 5d 29 0a 5c 65 6e 64 |ys.argv[|1]).\end|
|00001de0| 7b 76 65 72 62 61 74 69 | 6d 7d 0a 54 68 65 20 6c |{verbati|m}.The l|
|00001df0| 61 72 67 65 73 74 20 70 | 61 72 74 20 6f 66 20 74 |argest p|art of t|
|00001e00| 68 69 73 20 70 72 6f 67 | 72 61 6d 2c 20 69 6e 20 |his prog|ram, in |
|00001e10| 74 68 65 20 6d 69 64 64 | 6c 65 20 73 74 61 72 74 |the midd|le start|
|00001e20| 69 6e 67 20 77 69 74 68 | 20 7b 5c 74 74 0a 64 65 |ing with| {\tt.de|
|00001e30| 66 7d 2c 20 69 73 20 61 | 20 66 75 6e 63 74 69 6f |f}, is a| functio|
|00001e40| 6e 20 64 65 66 69 6e 69 | 74 69 6f 6e 2e 20 20 49 |n defini|tion. I|
|00001e50| 74 20 64 65 66 69 6e 65 | 73 20 61 20 66 75 6e 63 |t define|s a func|
|00001e60| 74 69 6f 6e 20 6e 61 6d | 65 64 20 7b 5c 74 74 20 |tion nam|ed {\tt |
|00001e70| 6c 73 7d 0a 77 69 74 68 | 20 61 20 73 69 6e 67 6c |ls}.with| a singl|
|00001e80| 65 20 70 61 72 61 6d 65 | 74 65 72 20 63 61 6c 6c |e parame|ter call|
|00001e90| 65 64 20 7b 5c 74 74 20 | 64 69 72 6e 61 6d 65 7d |ed {\tt |dirname}|
|00001ea0| 2e 20 20 28 43 6f 6d 6d | 65 6e 74 73 20 69 6e 20 |. (Comm|ents in |
|00001eb0| 50 79 74 68 6f 6e 0a 73 | 74 61 72 74 20 77 69 74 |Python.s|tart wit|
|00001ec0| 68 20 60 5c 23 27 20 61 | 6e 64 20 65 78 74 65 6e |h `\#' a|nd exten|
|00001ed0| 64 20 74 6f 20 74 68 65 | 20 65 6e 64 20 6f 66 20 |d to the| end of |
|00001ee0| 74 68 65 20 6c 69 6e 65 | 2e 29 20 20 54 68 65 20 |the line|.) The |
|00001ef0| 66 75 6e 63 74 69 6f 6e | 20 62 6f 64 79 0a 69 73 |function| body.is|
|00001f00| 20 69 6e 64 65 6e 74 65 | 64 3a 20 50 79 74 68 6f | indente|d: Pytho|
|00001f10| 6e 20 75 73 65 73 20 69 | 6e 64 65 6e 74 61 74 69 |n uses i|ndentati|
|00001f20| 6f 6e 20 66 6f 72 20 73 | 74 61 74 65 6d 65 6e 74 |on for s|tatement|
|00001f30| 20 67 72 6f 75 70 69 6e | 67 20 69 6e 73 74 65 61 | groupin|g instea|
|00001f40| 64 20 6f 66 0a 62 72 61 | 63 65 73 20 6f 72 20 62 |d of.bra|ces or b|
|00001f50| 65 67 69 6e 2f 65 6e 64 | 20 6b 65 79 77 6f 72 64 |egin/end| keyword|
|00001f60| 73 2e 20 20 54 68 69 73 | 20 69 73 20 73 68 6f 72 |s. This| is shor|
|00001f70| 74 65 72 20 74 6f 20 74 | 79 70 65 20 61 6e 64 20 |ter to t|ype and |
|00001f80| 61 76 6f 69 64 73 0a 66 | 72 75 73 74 72 61 74 69 |avoids.f|rustrati|
|00001f90| 6e 67 20 6d 69 73 6d 61 | 74 63 68 65 73 20 62 65 |ng misma|tches be|
|00001fa0| 74 77 65 65 6e 20 74 68 | 65 20 70 65 72 63 65 70 |tween th|e percep|
|00001fb0| 74 69 6f 6e 20 6f 66 20 | 67 72 6f 75 70 69 6e 67 |tion of |grouping|
|00001fc0| 20 62 79 20 74 68 65 20 | 75 73 65 72 0a 61 6e 64 | by the |user.and|
|00001fd0| 20 74 68 65 20 70 61 72 | 73 65 72 2e 20 20 50 79 | the par|ser. Py|
|00001fe0| 74 68 6f 6e 20 61 63 63 | 65 70 74 73 20 6f 6e 65 |thon acc|epts one|
|00001ff0| 20 73 74 61 74 65 6d 65 | 6e 74 20 70 65 72 20 6c | stateme|nt per l|
|00002000| 69 6e 65 3b 20 6c 6f 6e | 67 0a 73 74 61 74 65 6d |ine; lon|g.statem|
|00002010| 65 6e 74 73 20 6d 61 79 | 20 62 65 20 62 72 6f 6b |ents may| be brok|
|00002020| 65 6e 20 69 6e 20 70 69 | 65 63 65 73 20 75 73 69 |en in pi|eces usi|
|00002030| 6e 67 20 74 68 65 20 73 | 74 61 6e 64 61 72 64 20 |ng the s|tandard |
|00002040| 62 61 63 6b 73 6c 61 73 | 68 0a 63 6f 6e 76 65 6e |backslas|h.conven|
|00002050| 74 69 6f 6e 2e 20 20 49 | 66 20 74 68 65 20 62 6f |tion. I|f the bo|
|00002060| 64 79 20 6f 66 20 61 20 | 63 6f 6d 70 6f 75 6e 64 |dy of a |compound|
|00002070| 20 73 74 61 74 65 6d 65 | 6e 74 20 69 73 20 61 20 | stateme|nt is a |
|00002080| 73 69 6e 67 6c 65 2c 20 | 73 69 6d 70 6c 65 0a 73 |single, |simple.s|
|00002090| 74 61 74 65 6d 65 6e 74 | 2c 20 69 74 20 6d 61 79 |tatement|, it may|
|000020a0| 20 62 65 20 70 6c 61 63 | 65 64 20 6f 6e 20 74 68 | be plac|ed on th|
|000020b0| 65 20 73 61 6d 65 20 6c | 69 6e 65 20 61 73 20 74 |e same l|ine as t|
|000020c0| 68 65 20 68 65 61 64 2e | 0a 0a 54 68 65 20 66 69 |he head.|..The fi|
|000020d0| 72 73 74 20 73 74 61 74 | 65 6d 65 6e 74 20 6f 66 |rst stat|ement of|
|000020e0| 20 74 68 65 20 66 75 6e | 63 74 69 6f 6e 20 62 6f | the fun|ction bo|
|000020f0| 64 79 20 63 61 6c 6c 73 | 20 74 68 65 20 66 75 6e |dy calls| the fun|
|00002100| 63 74 69 6f 6e 20 7b 5c | 74 74 0a 6c 69 73 74 64 |ction {\|tt.listd|
|00002110| 69 72 7d 20 64 65 66 69 | 6e 65 64 20 69 6e 20 74 |ir} defi|ned in t|
|00002120| 68 65 20 6d 6f 64 75 6c | 65 20 7b 5c 74 74 20 70 |he modul|e {\tt p|
|00002130| 6f 73 69 78 7d 2e 20 20 | 54 68 69 73 20 66 75 6e |osix}. |This fun|
|00002140| 63 74 69 6f 6e 20 72 65 | 74 75 72 6e 73 20 61 0a |ction re|turns a.|
|00002150| 6c 69 73 74 20 6f 66 20 | 73 74 72 69 6e 67 73 20 |list of |strings |
|00002160| 72 65 70 72 65 73 65 6e | 74 69 6e 67 20 74 68 65 |represen|ting the|
|00002170| 20 63 6f 6e 74 65 6e 74 | 73 20 6f 66 20 74 68 65 | content|s of the|
|00002180| 20 64 69 72 65 63 74 6f | 72 79 20 6e 61 6d 65 20 | directo|ry name |
|00002190| 70 61 73 73 65 64 0a 61 | 73 20 61 20 73 74 72 69 |passed.a|s a stri|
|000021a0| 6e 67 20 61 72 67 75 6d | 65 6e 74 2c 20 68 65 72 |ng argum|ent, her|
|000021b0| 65 20 74 68 65 20 61 72 | 67 75 6d 65 6e 74 20 7b |e the ar|gument {|
|000021c0| 5c 74 74 20 64 69 72 6e | 61 6d 65 7d 2e 20 20 49 |\tt dirn|ame}. I|
|000021d0| 66 20 7b 5c 74 74 0a 64 | 69 72 6e 61 6d 65 7d 20 |f {\tt.d|irname} |
|000021e0| 77 65 72 65 20 6e 6f 74 | 20 61 20 76 61 6c 69 64 |were not| a valid|
|000021f0| 20 64 69 72 65 63 74 6f | 72 79 20 6e 61 6d 65 2c | directo|ry name,|
|00002200| 20 6f 72 20 70 65 72 68 | 61 70 73 20 6e 6f 74 20 | or perh|aps not |
|00002210| 65 76 65 6e 20 61 0a 73 | 74 72 69 6e 67 2c 20 7b |even a.s|tring, {|
|00002220| 5c 74 74 20 6c 69 73 74 | 64 69 72 7d 20 77 6f 75 |\tt list|dir} wou|
|00002230| 6c 64 20 72 61 69 73 65 | 20 61 6e 20 65 78 63 65 |ld raise| an exce|
|00002240| 70 74 69 6f 6e 20 61 6e | 64 20 74 68 65 20 6e 65 |ption an|d the ne|
|00002250| 78 74 20 73 74 61 74 65 | 6d 65 6e 74 0a 77 6f 75 |xt state|ment.wou|
|00002260| 6c 64 20 6e 65 76 65 72 | 20 62 65 20 72 65 61 63 |ld never| be reac|
|00002270| 68 65 64 2e 20 20 28 45 | 78 63 65 70 74 69 6f 6e |hed. (E|xception|
|00002280| 73 20 63 61 6e 20 62 65 | 20 63 61 75 67 68 74 20 |s can be| caught |
|00002290| 69 6e 20 50 79 74 68 6f | 6e 3b 20 73 65 65 0a 6c |in Pytho|n; see.l|
|000022a0| 61 74 65 72 2e 29 20 20 | 41 73 73 75 6d 69 6e 67 |ater.) |Assuming|
|000022b0| 20 7b 5c 74 74 20 6c 69 | 73 74 64 69 72 7d 20 72 | {\tt li|stdir} r|
|000022c0| 65 74 75 72 6e 73 20 6e | 6f 72 6d 61 6c 6c 79 2c |eturns n|ormally,|
|000022d0| 20 69 74 73 20 72 65 73 | 75 6c 74 20 69 73 0a 61 | its res|ult is.a|
|000022e0| 73 73 69 67 6e 65 64 20 | 74 6f 20 74 68 65 20 6c |ssigned |to the l|
|000022f0| 6f 63 61 6c 20 76 61 72 | 69 61 62 6c 65 20 7b 5c |ocal var|iable {\|
|00002300| 74 74 20 6e 61 6d 65 73 | 7d 2e 0a 0a 54 68 65 20 |tt names|}...The |
|00002310| 73 65 63 6f 6e 64 20 73 | 74 61 74 65 6d 65 6e 74 |second s|tatement|
|00002320| 20 63 61 6c 6c 73 20 74 | 68 65 20 6d 65 74 68 6f | calls t|he metho|
|00002330| 64 20 7b 5c 74 74 20 73 | 6f 72 74 7d 20 6f 66 20 |d {\tt s|ort} of |
|00002340| 74 68 65 20 76 61 72 69 | 61 62 6c 65 20 7b 5c 74 |the vari|able {\t|
|00002350| 74 0a 6e 61 6d 65 73 7d | 2e 20 20 54 68 69 73 20 |t.names}|. This |
|00002360| 6d 65 74 68 6f 64 20 69 | 73 20 64 65 66 69 6e 65 |method i|s define|
|00002370| 64 20 66 6f 72 20 61 6c | 6c 20 6c 69 73 74 73 20 |d for al|l lists |
|00002380| 69 6e 20 50 79 74 68 6f | 6e 20 61 6e 64 20 64 6f |in Pytho|n and do|
|00002390| 65 73 20 74 68 65 0a 6f | 62 76 69 6f 75 73 20 74 |es the.o|bvious t|
|000023a0| 68 69 6e 67 3a 20 74 68 | 65 20 65 6c 65 6d 65 6e |hing: th|e elemen|
|000023b0| 74 73 20 6f 66 20 74 68 | 65 20 6c 69 73 74 20 61 |ts of th|e list a|
|000023c0| 72 65 20 72 65 6f 72 64 | 65 72 65 64 20 61 63 63 |re reord|ered acc|
|000023d0| 6f 72 64 69 6e 67 20 74 | 6f 0a 74 68 65 69 72 20 |ording t|o.their |
|000023e0| 6e 61 74 75 72 61 6c 20 | 6f 72 64 65 72 69 6e 67 |natural |ordering|
|000023f0| 20 72 65 6c 61 74 69 6f | 6e 73 68 69 70 2e 20 20 | relatio|nship. |
|00002400| 53 69 6e 63 65 20 69 6e | 20 6f 75 72 20 65 78 61 |Since in| our exa|
|00002410| 6d 70 6c 65 20 74 68 65 | 20 6c 69 73 74 0a 63 6f |mple the| list.co|
|00002420| 6e 74 61 69 6e 73 20 73 | 74 72 69 6e 67 73 2c 20 |ntains s|trings, |
|00002430| 74 68 65 79 20 61 72 65 | 20 73 6f 72 74 65 64 20 |they are| sorted |
|00002440| 69 6e 20 61 73 63 65 6e | 64 69 6e 67 20 5c 41 53 |in ascen|ding \AS|
|00002450| 43 49 49 7b 7d 20 6f 72 | 64 65 72 2e 0a 0a 54 68 |CII{} or|der...Th|
|00002460| 65 20 6c 61 73 74 20 74 | 77 6f 20 6c 69 6e 65 73 |e last t|wo lines|
|00002470| 20 6f 66 20 74 68 65 20 | 66 75 6e 63 74 69 6f 6e | of the |function|
|00002480| 20 63 6f 6e 74 61 69 6e | 20 61 20 6c 6f 6f 70 20 | contain| a loop |
|00002490| 74 68 61 74 20 70 72 69 | 6e 74 73 20 61 6c 6c 0a |that pri|nts all.|
|000024a0| 65 6c 65 6d 65 6e 74 73 | 20 6f 66 20 74 68 65 20 |elements| of the |
|000024b0| 6c 69 73 74 20 77 68 6f | 73 65 20 66 69 72 73 74 |list who|se first|
|000024c0| 20 63 68 61 72 61 63 74 | 65 72 20 69 73 6e 27 74 | charact|er isn't|
|000024d0| 20 61 20 70 65 72 69 6f | 64 2e 20 20 49 6e 20 65 | a perio|d. In e|
|000024e0| 61 63 68 0a 69 74 65 72 | 61 74 69 6f 6e 2c 20 74 |ach.iter|ation, t|
|000024f0| 68 65 20 7b 5c 74 74 20 | 66 6f 72 7d 20 73 74 61 |he {\tt |for} sta|
|00002500| 74 65 6d 65 6e 74 20 61 | 73 73 69 67 6e 73 20 61 |tement a|ssigns a|
|00002510| 6e 20 65 6c 65 6d 65 6e | 74 20 6f 66 20 74 68 65 |n elemen|t of the|
|00002520| 20 6c 69 73 74 20 74 6f | 0a 74 68 65 20 6c 6f 63 | list to|.the loc|
|00002530| 61 6c 20 76 61 72 69 61 | 62 6c 65 20 7b 5c 74 74 |al varia|ble {\tt|
|00002540| 20 6e 61 6d 65 7d 2e 20 | 20 54 68 65 20 7b 5c 74 | name}. | The {\t|
|00002550| 74 20 70 72 69 6e 74 7d | 20 73 74 61 74 65 6d 65 |t print}| stateme|
|00002560| 6e 74 20 69 73 20 69 6e | 74 65 6e 64 65 64 0a 66 |nt is in|tended.f|
|00002570| 6f 72 20 73 69 6d 70 6c | 65 2d 6d 69 6e 64 65 64 |or simpl|e-minded|
|00002580| 20 6f 75 74 70 75 74 3b | 20 6d 6f 72 65 20 65 6c | output;| more el|
|00002590| 61 62 6f 72 61 74 65 20 | 66 6f 72 6d 61 74 74 69 |aborate |formatti|
|000025a0| 6e 67 20 69 73 20 70 6f | 73 73 69 62 6c 65 20 77 |ng is po|ssible w|
|000025b0| 69 74 68 0a 50 79 74 68 | 6f 6e 27 73 20 73 74 72 |ith.Pyth|on's str|
|000025c0| 69 6e 67 20 68 61 6e 64 | 6c 69 6e 67 20 66 75 6e |ing hand|ling fun|
|000025d0| 63 74 69 6f 6e 73 2e 0a | 0a 54 68 65 20 6f 74 68 |ctions..|.The oth|
|000025e0| 65 72 20 74 77 6f 20 70 | 61 72 74 73 20 6f 66 20 |er two p|arts of |
|000025f0| 74 68 65 20 70 72 6f 67 | 72 61 6d 20 61 72 65 20 |the prog|ram are |
|00002600| 65 61 73 69 6c 79 20 65 | 78 70 6c 61 69 6e 65 64 |easily e|xplained|
|00002610| 2e 20 20 54 68 65 20 66 | 69 72 73 74 0a 6c 69 6e |. The f|irst.lin|
|00002620| 65 20 69 73 20 61 6e 20 | 7b 5c 74 74 20 69 6d 70 |e is an |{\tt imp|
|00002630| 6f 72 74 7d 20 73 74 61 | 74 65 6d 65 6e 74 20 74 |ort} sta|tement t|
|00002640| 68 61 74 20 74 65 6c 6c | 73 20 74 68 65 20 69 6e |hat tell|s the in|
|00002650| 74 65 72 70 72 65 74 65 | 72 20 74 6f 20 69 6d 70 |terprete|r to imp|
|00002660| 6f 72 74 0a 74 68 65 20 | 6d 6f 64 75 6c 65 73 20 |ort.the |modules |
|00002670| 7b 5c 74 74 20 73 79 73 | 7d 20 61 6e 64 20 7b 5c |{\tt sys|} and {\|
|00002680| 74 74 20 70 6f 73 69 78 | 7d 2e 20 20 41 73 20 69 |tt posix|}. As i|
|00002690| 74 20 68 61 70 70 65 6e | 73 20 74 68 65 73 65 20 |t happen|s these |
|000026a0| 61 72 65 20 62 6f 74 68 | 0a 62 75 69 6c 74 20 69 |are both|.built i|
|000026b0| 6e 74 6f 20 74 68 65 20 | 69 6e 74 65 72 70 72 65 |nto the |interpre|
|000026c0| 74 65 72 2e 20 20 49 6d | 70 6f 72 74 69 6e 67 20 |ter. Im|porting |
|000026d0| 61 20 6d 6f 64 75 6c 65 | 20 28 62 75 69 6c 74 2d |a module| (built-|
|000026e0| 69 6e 20 6f 72 0a 6f 74 | 68 65 72 77 69 73 65 29 |in or.ot|herwise)|
|000026f0| 20 6f 6e 6c 79 20 6d 61 | 6b 65 73 20 74 68 65 20 | only ma|kes the |
|00002700| 6d 6f 64 75 6c 65 20 6e | 61 6d 65 20 61 76 61 69 |module n|ame avai|
|00002710| 6c 61 62 6c 65 20 69 6e | 20 74 68 65 20 63 75 72 |lable in| the cur|
|00002720| 72 65 6e 74 20 73 63 6f | 70 65 3b 0a 66 75 6e 63 |rent sco|pe;.func|
|00002730| 74 69 6f 6e 73 20 61 6e | 64 20 64 61 74 61 20 64 |tions an|d data d|
|00002740| 65 66 69 6e 65 64 20 69 | 6e 20 74 68 65 20 6d 6f |efined i|n the mo|
|00002750| 64 75 6c 65 20 61 72 65 | 20 61 63 63 65 73 73 65 |dule are| accesse|
|00002760| 64 20 74 68 72 6f 75 67 | 68 20 74 68 65 20 64 6f |d throug|h the do|
|00002770| 74 0a 6e 6f 74 61 74 69 | 6f 6e 20 61 73 20 69 6e |t.notati|on as in|
|00002780| 20 7b 5c 74 74 20 70 6f | 73 69 78 2e 6c 69 73 74 | {\tt po|six.list|
|00002790| 64 69 72 7d 2e 20 20 54 | 68 65 20 73 63 6f 70 65 |dir}. T|he scope|
|000027a0| 20 72 75 6c 65 73 20 6f | 66 20 50 79 74 68 6f 6e | rules o|f Python|
|000027b0| 20 61 72 65 0a 73 75 63 | 68 20 74 68 61 74 20 74 | are.suc|h that t|
|000027c0| 68 65 20 69 6d 70 6f 72 | 74 65 64 20 6d 6f 64 75 |he impor|ted modu|
|000027d0| 6c 65 20 6e 61 6d 65 20 | 7b 5c 74 74 20 70 6f 73 |le name |{\tt pos|
|000027e0| 69 78 7d 20 69 73 20 61 | 6c 73 6f 20 61 76 61 69 |ix} is a|lso avai|
|000027f0| 6c 61 62 6c 65 20 69 6e | 0a 74 68 65 20 66 75 6e |lable in|.the fun|
|00002800| 63 74 69 6f 6e 20 7b 5c | 74 74 20 6c 73 7d 20 28 |ction {\|tt ls} (|
|00002810| 74 68 69 73 20 77 69 6c | 6c 20 62 65 20 64 69 73 |this wil|l be dis|
|00002820| 63 75 73 73 65 64 20 69 | 6e 20 6d 6f 72 65 20 64 |cussed i|n more d|
|00002830| 65 74 61 69 6c 20 6c 61 | 74 65 72 29 2e 0a 0a 46 |etail la|ter)...F|
|00002840| 69 6e 61 6c 6c 79 2c 20 | 74 68 65 20 6c 61 73 74 |inally, |the last|
|00002850| 20 6c 69 6e 65 20 6f 66 | 20 74 68 65 20 70 72 6f | line of| the pro|
|00002860| 67 72 61 6d 20 63 61 6c | 6c 73 20 74 68 65 20 7b |gram cal|ls the {|
|00002870| 5c 74 74 20 6c 73 7d 20 | 66 75 6e 63 74 69 6f 6e |\tt ls} |function|
|00002880| 20 77 69 74 68 0a 61 20 | 64 65 66 69 6e 69 74 65 | with.a |definite|
|00002890| 20 61 72 67 75 6d 65 6e | 74 2e 20 20 49 74 20 6d | argumen|t. It m|
|000028a0| 75 73 74 20 62 65 20 6c | 61 73 74 20 73 69 6e 63 |ust be l|ast sinc|
|000028b0| 65 20 50 79 74 68 6f 6e | 20 6f 62 6a 65 63 74 73 |e Python| objects|
|000028c0| 20 6d 75 73 74 20 62 65 | 0a 64 65 66 69 6e 65 64 | must be|.defined|
|000028d0| 20 62 65 66 6f 72 65 20 | 74 68 65 79 20 63 61 6e | before |they can|
|000028e0| 20 62 65 20 75 73 65 64 | 3b 20 69 6e 20 70 61 72 | be used|; in par|
|000028f0| 74 69 63 75 6c 61 72 2c | 20 74 68 65 20 66 75 6e |ticular,| the fun|
|00002900| 63 74 69 6f 6e 20 7b 5c | 74 74 20 6c 73 7d 0a 6d |ction {\|tt ls}.m|
|00002910| 75 73 74 20 62 65 20 64 | 65 66 69 6e 65 64 20 62 |ust be d|efined b|
|00002920| 65 66 6f 72 65 20 69 74 | 20 63 61 6e 20 62 65 20 |efore it| can be |
|00002930| 63 61 6c 6c 65 64 2e 20 | 20 54 68 65 20 61 72 67 |called. | The arg|
|00002940| 75 6d 65 6e 74 20 74 6f | 20 7b 5c 74 74 20 6c 73 |ument to| {\tt ls|
|00002950| 7d 20 69 73 0a 7b 5c 74 | 74 20 73 79 73 2e 61 72 |} is.{\t|t sys.ar|
|00002960| 67 76 5b 31 5d 7d 2c 20 | 77 68 69 63 68 20 68 61 |gv[1]}, |which ha|
|00002970| 70 70 65 6e 73 20 74 6f | 20 62 65 20 74 68 65 20 |ppens to| be the |
|00002980| 50 79 74 68 6f 6e 20 65 | 71 75 69 76 61 6c 65 6e |Python e|quivalen|
|00002990| 74 20 6f 66 20 7b 5c 74 | 74 0a 5c 24 31 7d 20 69 |t of {\t|t.\$1} i|
|000029a0| 6e 20 61 20 73 68 65 6c | 6c 20 73 63 72 69 70 74 |n a shel|l script|
|000029b0| 20 6f 72 20 7b 5c 74 74 | 20 61 72 67 76 5b 31 5d | or {\tt| argv[1]|
|000029c0| 7d 20 69 6e 20 61 20 43 | 20 70 72 6f 67 72 61 6d |} in a C| program|
|000029d0| 27 73 20 7b 5c 74 74 20 | 6d 61 69 6e 7d 0a 66 75 |'s {\tt |main}.fu|
|000029e0| 6e 63 74 69 6f 6e 2e 0a | 0a 5c 73 75 62 73 65 63 |nction..|.\subsec|
|000029f0| 74 69 6f 6e 7b 50 79 74 | 68 6f 6e 20 44 61 74 61 |tion{Pyt|hon Data|
|00002a00| 20 54 79 70 65 73 7d 0a | 0a 28 54 68 69 73 20 61 | Types}.|.(This a|
|00002a10| 6e 64 20 74 68 65 20 66 | 6f 6c 6c 6f 77 69 6e 67 |nd the f|ollowing|
|00002a20| 20 73 75 62 73 65 63 74 | 69 6f 6e 73 20 64 65 73 | subsect|ions des|
|00002a30| 63 72 69 62 65 20 50 79 | 74 68 6f 6e 20 69 6e 20 |cribe Py|thon in |
|00002a40| 71 75 69 74 65 20 61 20 | 6c 6f 74 20 6f 66 0a 64 |quite a |lot of.d|
|00002a50| 65 74 61 69 6c 2e 20 20 | 49 66 20 79 6f 75 20 61 |etail. |If you a|
|00002a60| 72 65 20 6d 6f 72 65 20 | 69 6e 74 65 72 65 73 74 |re more |interest|
|00002a70| 65 64 20 69 6e 20 41 49 | 4c 2c 20 41 6d 6f 65 62 |ed in AI|L, Amoeb|
|00002a80| 61 20 61 6e 64 20 68 6f | 77 20 74 68 65 79 20 61 |a and ho|w they a|
|00002a90| 72 65 0a 6c 69 6e 6b 65 | 64 20 77 69 74 68 20 50 |re.linke|d with P|
|00002aa0| 79 74 68 6f 6e 2c 20 79 | 6f 75 20 63 61 6e 20 73 |ython, y|ou can s|
|00002ab0| 6b 69 70 20 74 6f 20 73 | 65 63 74 69 6f 6e 20 33 |kip to s|ection 3|
|00002ac0| 20 6e 6f 77 2e 29 0a 0a | 50 79 74 68 6f 6e 27 73 | now.)..|Python's|
|00002ad0| 20 73 79 6e 74 61 78 20 | 6d 61 79 20 6e 6f 74 20 | syntax |may not |
|00002ae0| 68 61 76 65 20 62 69 67 | 20 73 75 72 70 72 69 73 |have big| surpris|
|00002af0| 65 73 20 28 77 68 69 63 | 68 20 69 73 20 65 78 61 |es (whic|h is exa|
|00002b00| 63 74 6c 79 20 61 73 20 | 69 74 0a 73 68 6f 75 6c |ctly as |it.shoul|
|00002b10| 64 20 62 65 29 2c 20 62 | 75 74 20 69 74 73 20 64 |d be), b|ut its d|
|00002b20| 61 74 61 20 74 79 70 65 | 73 20 61 72 65 20 71 75 |ata type|s are qu|
|00002b30| 69 74 65 20 64 69 66 66 | 65 72 65 6e 74 20 66 72 |ite diff|erent fr|
|00002b40| 6f 6d 20 77 68 61 74 20 | 69 73 20 66 6f 75 6e 64 |om what |is found|
|00002b50| 0a 69 6e 20 6c 61 6e 67 | 75 61 67 65 73 20 6c 69 |.in lang|uages li|
|00002b60| 6b 65 20 43 2c 20 41 64 | 61 20 6f 72 20 4d 6f 64 |ke C, Ad|a or Mod|
|00002b70| 75 6c 61 2d 33 2e 20 20 | 41 6c 6c 20 64 61 74 61 |ula-3. |All data|
|00002b80| 20 74 79 70 65 73 20 69 | 6e 20 50 79 74 68 6f 6e | types i|n Python|
|00002b90| 2c 20 65 76 65 6e 0a 69 | 6e 74 65 67 65 72 73 2c |, even.i|ntegers,|
|00002ba0| 20 61 72 65 20 60 6f 62 | 6a 65 63 74 73 27 2e 20 | are `ob|jects'. |
|00002bb0| 20 41 6c 6c 20 6f 62 6a | 65 63 74 73 20 70 61 72 | All obj|ects par|
|00002bc0| 74 69 63 69 70 61 74 65 | 20 69 6e 20 61 20 63 6f |ticipate| in a co|
|00002bd0| 6d 6d 6f 6e 20 67 61 72 | 62 61 67 65 0a 63 6f 6c |mmon gar|bage.col|
|00002be0| 6c 65 63 74 69 6f 6e 20 | 73 63 68 65 6d 65 20 28 |lection |scheme (|
|00002bf0| 63 75 72 72 65 6e 74 6c | 79 20 69 6d 70 6c 65 6d |currentl|y implem|
|00002c00| 65 6e 74 65 64 20 75 73 | 69 6e 67 20 72 65 66 65 |ented us|ing refe|
|00002c10| 72 65 6e 63 65 20 63 6f | 75 6e 74 69 6e 67 29 2e |rence co|unting).|
|00002c20| 0a 41 73 73 69 67 6e 6d | 65 6e 74 20 69 73 20 63 |.Assignm|ent is c|
|00002c30| 68 65 61 70 2c 20 69 6e | 64 65 70 65 6e 64 65 6e |heap, in|dependen|
|00002c40| 74 20 6f 66 20 6f 62 6a | 65 63 74 20 73 69 7a 65 |t of obj|ect size|
|00002c50| 20 61 6e 64 20 74 79 70 | 65 3a 20 6f 6e 6c 79 20 | and typ|e: only |
|00002c60| 61 0a 70 6f 69 6e 74 65 | 72 20 74 6f 20 74 68 65 |a.pointe|r to the|
|00002c70| 20 61 73 73 69 67 6e 65 | 64 20 6f 62 6a 65 63 74 | assigne|d object|
|00002c80| 20 69 73 20 73 74 6f 72 | 65 64 20 69 6e 20 74 68 | is stor|ed in th|
|00002c90| 65 20 61 73 73 69 67 6e | 65 64 2d 74 6f 20 76 61 |e assign|ed-to va|
|00002ca0| 72 69 61 62 6c 65 2e 0a | 4e 6f 20 74 79 70 65 20 |riable..|No type |
|00002cb0| 63 68 65 63 6b 69 6e 67 | 20 69 73 20 70 65 72 66 |checking| is perf|
|00002cc0| 6f 72 6d 65 64 20 6f 6e | 20 61 73 73 69 67 6e 6d |ormed on| assignm|
|00002cd0| 65 6e 74 3b 20 6f 6e 6c | 79 20 73 70 65 63 69 66 |ent; onl|y specif|
|00002ce0| 69 63 20 6f 70 65 72 61 | 74 69 6f 6e 73 0a 6c 69 |ic opera|tions.li|
|00002cf0| 6b 65 20 61 64 64 69 74 | 69 6f 6e 20 74 65 73 74 |ke addit|ion test|
|00002d00| 20 66 6f 72 20 70 61 72 | 74 69 63 75 6c 61 72 20 | for par|ticular |
|00002d10| 6f 70 65 72 61 6e 64 20 | 74 79 70 65 73 2e 0a 0a |operand |types...|
|00002d20| 54 68 65 20 62 61 73 69 | 63 20 6f 62 6a 65 63 74 |The basi|c object|
|00002d30| 20 74 79 70 65 73 20 69 | 6e 20 50 79 74 68 6f 6e | types i|n Python|
|00002d40| 20 61 72 65 20 6e 75 6d | 62 65 72 73 2c 20 73 74 | are num|bers, st|
|00002d50| 72 69 6e 67 73 2c 20 74 | 75 70 6c 65 73 2c 20 6c |rings, t|uples, l|
|00002d60| 69 73 74 73 0a 61 6e 64 | 20 64 69 63 74 69 6f 6e |ists.and| diction|
|00002d70| 61 72 69 65 73 2e 20 20 | 53 6f 6d 65 20 6f 74 68 |aries. |Some oth|
|00002d80| 65 72 20 6f 62 6a 65 63 | 74 20 74 79 70 65 73 20 |er objec|t types |
|00002d90| 61 72 65 20 6f 70 65 6e | 20 66 69 6c 65 73 2c 20 |are open| files, |
|00002da0| 66 75 6e 63 74 69 6f 6e | 73 2c 0a 6d 6f 64 75 6c |function|s,.modul|
|00002db0| 65 73 2c 20 63 6c 61 73 | 73 65 73 2c 20 61 6e 64 |es, clas|ses, and|
|00002dc0| 20 63 6c 61 73 73 20 69 | 6e 73 74 61 6e 63 65 73 | class i|nstances|
|00002dd0| 3b 20 65 76 65 6e 20 74 | 79 70 65 73 20 74 68 65 |; even t|ypes the|
|00002de0| 6d 73 65 6c 76 65 73 20 | 61 72 65 0a 72 65 70 72 |mselves |are.repr|
|00002df0| 65 73 65 6e 74 65 64 20 | 61 73 20 6f 62 6a 65 63 |esented |as objec|
|00002e00| 74 73 2e 20 20 45 78 74 | 65 6e 73 69 6f 6e 20 6d |ts. Ext|ension m|
|00002e10| 6f 64 75 6c 65 73 20 77 | 72 69 74 74 65 6e 20 69 |odules w|ritten i|
|00002e20| 6e 20 43 20 63 61 6e 20 | 64 65 66 69 6e 65 0a 61 |n C can |define.a|
|00002e30| 64 64 69 74 69 6f 6e 61 | 6c 20 6f 62 6a 65 63 74 |dditiona|l object|
|00002e40| 20 74 79 70 65 73 3b 20 | 65 78 61 6d 70 6c 65 73 | types; |examples|
|00002e50| 20 61 72 65 20 6f 62 6a | 65 63 74 73 20 72 65 70 | are obj|ects rep|
|00002e60| 72 65 73 65 6e 74 69 6e | 67 20 77 69 6e 64 6f 77 |resentin|g window|
|00002e70| 73 20 61 6e 64 0a 41 6d | 6f 65 62 61 20 63 61 70 |s and.Am|oeba cap|
|00002e80| 61 62 69 6c 69 74 69 65 | 73 2e 20 20 46 69 6e 61 |abilitie|s. Fina|
|00002e90| 6c 6c 79 2c 20 74 68 65 | 20 69 6d 70 6c 65 6d 65 |lly, the| impleme|
|00002ea0| 6e 74 61 74 69 6f 6e 20 | 69 74 73 65 6c 66 20 6d |ntation |itself m|
|00002eb0| 61 6b 65 73 20 68 65 61 | 76 79 0a 75 73 65 20 6f |akes hea|vy.use o|
|00002ec0| 66 20 6f 62 6a 65 63 74 | 73 2c 20 61 6e 64 20 64 |f object|s, and d|
|00002ed0| 65 66 69 6e 65 73 20 73 | 6f 6d 65 20 70 72 69 76 |efines s|ome priv|
|00002ee0| 61 74 65 20 6f 62 6a 65 | 63 74 20 74 79 70 65 73 |ate obje|ct types|
|00002ef0| 20 74 68 61 74 20 61 72 | 65 6e 27 74 0a 6e 6f 72 | that ar|en't.nor|
|00002f00| 6d 61 6c 6c 79 20 76 69 | 73 69 62 6c 65 20 74 6f |mally vi|sible to|
|00002f10| 20 74 68 65 20 75 73 65 | 72 2e 20 20 54 68 65 72 | the use|r. Ther|
|00002f20| 65 20 69 73 20 6e 6f 20 | 65 78 70 6c 69 63 69 74 |e is no |explicit|
|00002f30| 20 70 6f 69 6e 74 65 72 | 20 74 79 70 65 20 69 6e | pointer| type in|
|00002f40| 0a 50 79 74 68 6f 6e 2e | 0a 0a 7b 5c 65 6d 20 4e |.Python.|..{\em N|
|00002f50| 75 6d 62 65 72 73 7d 2c | 20 62 6f 74 68 20 69 6e |umbers},| both in|
|00002f60| 74 65 67 65 72 73 20 61 | 6e 64 20 66 6c 6f 61 74 |tegers a|nd float|
|00002f70| 69 6e 67 20 70 6f 69 6e | 74 2c 20 61 72 65 20 70 |ing poin|t, are p|
|00002f80| 72 65 74 74 79 0a 73 74 | 72 61 69 67 68 74 66 6f |retty.st|raightfo|
|00002f90| 72 77 61 72 64 2e 20 20 | 54 68 65 20 6e 6f 74 61 |rward. |The nota|
|00002fa0| 74 69 6f 6e 20 66 6f 72 | 20 6e 75 6d 65 72 69 63 |tion for| numeric|
|00002fb0| 20 6c 69 74 65 72 61 6c | 73 20 69 73 20 74 68 65 | literal|s is the|
|00002fc0| 20 73 61 6d 65 20 61 73 | 20 69 6e 0a 43 2c 20 69 | same as| in.C, i|
|00002fd0| 6e 63 6c 75 64 69 6e 67 | 20 6f 63 74 61 6c 20 61 |ncluding| octal a|
|00002fe0| 6e 64 20 68 65 78 61 64 | 65 63 69 6d 61 6c 20 69 |nd hexad|ecimal i|
|00002ff0| 6e 74 65 67 65 72 73 3b | 20 70 72 65 63 69 73 69 |ntegers;| precisi|
|00003000| 6f 6e 20 69 73 20 74 68 | 65 20 73 61 6d 65 20 61 |on is th|e same a|
|00003010| 73 0a 7b 5c 74 74 20 6c | 6f 6e 67 7d 20 6f 72 20 |s.{\tt l|ong} or |
|00003020| 7b 5c 74 74 20 64 6f 75 | 62 6c 65 7d 20 69 6e 20 |{\tt dou|ble} in |
|00003030| 43 5c 40 2e 20 20 41 20 | 74 68 69 72 64 20 6e 75 |C\@. A |third nu|
|00003040| 6d 65 72 69 63 20 74 79 | 70 65 2c 20 60 6c 6f 6e |meric ty|pe, `lon|
|00003050| 67 0a 69 6e 74 65 67 65 | 72 27 2c 20 77 72 69 74 |g.intege|r', writ|
|00003060| 74 65 6e 20 77 69 74 68 | 20 61 6e 20 60 4c 27 20 |ten with| an `L' |
|00003070| 73 75 66 66 69 78 2c 20 | 63 61 6e 20 62 65 20 75 |suffix, |can be u|
|00003080| 73 65 64 20 66 6f 72 20 | 61 72 62 69 74 72 61 72 |sed for |arbitrar|
|00003090| 79 0a 70 72 65 63 69 73 | 69 6f 6e 20 63 61 6c 63 |y.precis|ion calc|
|000030a0| 75 6c 61 74 69 6f 6e 73 | 2e 20 20 41 6c 6c 20 61 |ulations|. All a|
|000030b0| 72 69 74 68 6d 65 74 69 | 63 2c 20 73 68 69 66 74 |rithmeti|c, shift|
|000030c0| 69 6e 67 20 61 6e 64 20 | 6d 61 73 6b 69 6e 67 0a |ing and |masking.|
|000030d0| 6f 70 65 72 61 74 69 6f | 6e 73 20 66 72 6f 6d 20 |operatio|ns from |
|000030e0| 43 20 61 72 65 20 73 75 | 70 70 6f 72 74 65 64 2e |C are su|pported.|
|000030f0| 0a 0a 7b 5c 65 6d 20 53 | 74 72 69 6e 67 73 7d 20 |..{\em S|trings} |
|00003100| 61 72 65 20 60 70 72 69 | 6d 69 74 69 76 65 27 20 |are `pri|mitive' |
|00003110| 6f 62 6a 65 63 74 73 20 | 6a 75 73 74 20 6c 69 6b |objects |just lik|
|00003120| 65 20 6e 75 6d 62 65 72 | 73 2e 20 20 53 74 72 69 |e number|s. Stri|
|00003130| 6e 67 0a 6c 69 74 65 72 | 61 6c 73 20 61 72 65 20 |ng.liter|als are |
|00003140| 77 72 69 74 74 65 6e 20 | 62 65 74 77 65 65 6e 20 |written |between |
|00003150| 73 69 6e 67 6c 65 20 71 | 75 6f 74 65 73 2c 20 75 |single q|uotes, u|
|00003160| 73 69 6e 67 20 73 69 6d | 69 6c 61 72 20 65 73 63 |sing sim|ilar esc|
|00003170| 61 70 65 0a 73 65 71 75 | 65 6e 63 65 73 20 61 73 |ape.sequ|ences as|
|00003180| 20 69 6e 20 43 5c 40 2e | 20 20 4f 70 65 72 61 74 | in C\@.| Operat|
|00003190| 69 6f 6e 73 20 61 72 65 | 20 62 75 69 6c 74 20 69 |ions are| built i|
|000031a0| 6e 74 6f 20 74 68 65 20 | 6c 61 6e 67 75 61 67 65 |nto the |language|
|000031b0| 20 74 6f 0a 63 6f 6e 63 | 61 74 65 6e 61 74 65 20 | to.conc|atenate |
|000031c0| 61 6e 64 20 74 6f 20 72 | 65 70 6c 69 63 61 74 65 |and to r|eplicate|
|000031d0| 20 73 74 72 69 6e 67 73 | 2c 20 74 6f 20 65 78 74 | strings|, to ext|
|000031e0| 72 61 63 74 20 73 75 62 | 73 74 72 69 6e 67 73 2c |ract sub|strings,|
|000031f0| 20 65 74 63 2e 0a 54 68 | 65 72 65 20 69 73 20 6e | etc..Th|ere is n|
|00003200| 6f 20 6c 69 6d 69 74 20 | 74 6f 20 74 68 65 20 6c |o limit |to the l|
|00003210| 65 6e 67 74 68 20 6f 66 | 20 74 68 65 20 73 74 72 |ength of| the str|
|00003220| 69 6e 67 73 20 63 72 65 | 61 74 65 64 20 62 79 20 |ings cre|ated by |
|00003230| 61 20 70 72 6f 67 72 61 | 6d 2e 0a 54 68 65 72 65 |a progra|m..There|
|00003240| 20 69 73 20 6e 6f 20 73 | 65 70 61 72 61 74 65 20 | is no s|eparate |
|00003250| 63 68 61 72 61 63 74 65 | 72 20 64 61 74 61 20 74 |characte|r data t|
|00003260| 79 70 65 3b 20 73 74 72 | 69 6e 67 73 20 6f 66 20 |ype; str|ings of |
|00003270| 6c 65 6e 67 74 68 20 6f | 6e 65 20 64 6f 0a 6e 69 |length o|ne do.ni|
|00003280| 63 65 6c 79 2e 0a 0a 7b | 5c 65 6d 20 54 75 70 6c |cely...{|\em Tupl|
|00003290| 65 73 7d 20 61 72 65 20 | 61 20 77 61 79 20 74 6f |es} are |a way to|
|000032a0| 20 60 70 61 63 6b 27 20 | 73 6d 61 6c 6c 20 61 6d | `pack' |small am|
|000032b0| 6f 75 6e 74 73 20 6f 66 | 20 68 65 74 65 72 6f 67 |ounts of| heterog|
|000032c0| 65 6e 65 6f 75 73 20 64 | 61 74 61 0a 74 6f 67 65 |eneous d|ata.toge|
|000032d0| 74 68 65 72 20 61 6e 64 | 20 63 61 72 72 79 20 74 |ther and| carry t|
|000032e0| 68 65 6d 20 61 72 6f 75 | 6e 64 20 61 73 20 61 20 |hem arou|nd as a |
|000032f0| 75 6e 69 74 2e 20 20 55 | 6e 6c 69 6b 65 20 73 74 |unit. U|nlike st|
|00003300| 72 75 63 74 75 72 65 20 | 6d 65 6d 62 65 72 73 20 |ructure |members |
|00003310| 69 6e 0a 43 2c 20 74 75 | 70 6c 65 20 69 74 65 6d |in.C, tu|ple item|
|00003320| 73 20 61 72 65 20 6e 61 | 6d 65 6c 65 73 73 2e 20 |s are na|meless. |
|00003330| 20 50 61 63 6b 69 6e 67 | 20 61 6e 64 20 75 6e 70 | Packing| and unp|
|00003340| 61 63 6b 69 6e 67 20 61 | 73 73 69 67 6e 6d 65 6e |acking a|ssignmen|
|00003350| 74 73 20 61 6c 6c 6f 77 | 0a 61 63 63 65 73 73 20 |ts allow|.access |
|00003360| 74 6f 20 74 68 65 20 69 | 74 65 6d 73 2c 20 66 6f |to the i|tems, fo|
|00003370| 72 20 65 78 61 6d 70 6c | 65 3a 0a 5c 62 65 67 69 |r exampl|e:.\begi|
|00003380| 6e 7b 76 65 72 62 61 74 | 69 6d 7d 0a 78 20 3d 20 |n{verbat|im}.x = |
|00003390| 27 48 69 27 2c 20 28 31 | 2c 20 32 29 2c 20 27 57 |'Hi', (1|, 2), 'W|
|000033a0| 6f 72 6c 64 27 20 20 20 | 23 20 78 20 69 73 20 61 |orld' |# x is a|
|000033b0| 20 33 2d 69 74 65 6d 20 | 74 75 70 6c 65 2c 0a 20 | 3-item |tuple,. |
|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 20 20 23 20 69 74 73 | | # its|
|000033e0| 20 6d 69 64 64 6c 65 20 | 69 74 65 6d 20 69 73 20 | middle |item is |
|000033f0| 28 31 2c 20 32 29 0a 70 | 2c 20 71 2c 20 72 20 3d |(1, 2).p|, q, r =|
|00003400| 20 78 20 20 20 20 20 20 | 20 20 20 20 20 20 20 20 | x | |
|00003410| 20 20 20 23 20 75 6e 70 | 61 63 6b 20 78 20 69 6e | # unp|ack x in|
|00003420| 74 6f 20 70 2c 20 71 20 | 61 6e 64 20 72 0a 61 2c |to p, q |and r.a,|
|00003430| 20 62 20 3d 20 71 20 20 | 20 20 20 20 20 20 20 20 | b = q | |
|00003440| 20 20 20 20 20 20 20 20 | 20 20 23 20 75 6e 70 61 | | # unpa|
|00003450| 63 6b 20 71 20 69 6e 74 | 6f 20 61 20 61 6e 64 20 |ck q int|o a and |
|00003460| 62 0a 5c 65 6e 64 7b 76 | 65 72 62 61 74 69 6d 7d |b.\end{v|erbatim}|
|00003470| 0a 41 20 63 6f 6d 62 69 | 6e 61 74 69 6f 6e 20 6f |.A combi|nation o|
|00003480| 66 20 70 61 63 6b 69 6e | 67 20 61 6e 64 20 75 6e |f packin|g and un|
|00003490| 70 61 63 6b 69 6e 67 20 | 61 73 73 69 67 6e 6d 65 |packing |assignme|
|000034a0| 6e 74 20 63 61 6e 20 62 | 65 20 75 73 65 64 20 61 |nt can b|e used a|
|000034b0| 73 0a 70 61 72 61 6c 6c | 65 6c 20 61 73 73 69 67 |s.parall|el assig|
|000034c0| 6e 6d 65 6e 74 2c 20 61 | 6e 64 20 69 73 20 69 64 |nment, a|nd is id|
|000034d0| 69 6f 6d 20 66 6f 72 20 | 70 65 72 6d 75 74 61 74 |iom for |permutat|
|000034e0| 69 6f 6e 73 2c 20 65 2e | 67 2e 3a 0a 5c 62 65 67 |ions, e.|g.:.\beg|
|000034f0| 69 6e 7b 76 65 72 62 61 | 74 69 6d 7d 0a 70 2c 20 |in{verba|tim}.p, |
|00003500| 71 20 3d 20 71 2c 20 70 | 20 20 20 20 20 20 20 20 |q = q, p| |
|00003510| 20 20 20 20 20 20 20 20 | 20 23 20 73 77 61 70 20 | | # swap |
|00003520| 77 69 74 68 6f 75 74 20 | 74 65 6d 70 6f 72 61 72 |without |temporar|
|00003530| 79 0a 61 2c 20 62 2c 20 | 63 20 3d 20 62 2c 20 63 |y.a, b, |c = b, c|
|00003540| 2c 20 61 20 20 20 20 20 | 20 20 20 20 20 20 23 20 |, a | # |
|00003550| 63 79 63 6c 69 63 20 70 | 65 72 6d 75 74 61 74 69 |cyclic p|ermutati|
|00003560| 6f 6e 0a 5c 65 6e 64 7b | 76 65 72 62 61 74 69 6d |on.\end{|verbatim|
|00003570| 7d 0a 54 75 70 6c 65 73 | 20 61 72 65 20 61 6c 73 |}.Tuples| are als|
|00003580| 6f 20 75 73 65 64 20 66 | 6f 72 20 66 75 6e 63 74 |o used f|or funct|
|00003590| 69 6f 6e 20 61 72 67 75 | 6d 65 6e 74 20 6c 69 73 |ion argu|ment lis|
|000035a0| 74 73 20 69 66 20 74 68 | 65 72 65 20 69 73 20 6d |ts if th|ere is m|
|000035b0| 6f 72 65 20 74 68 61 6e | 0a 6f 6e 65 20 61 72 67 |ore than|.one arg|
|000035c0| 75 6d 65 6e 74 2e 20 20 | 41 20 74 75 70 6c 65 20 |ument. |A tuple |
|000035d0| 6f 62 6a 65 63 74 2c 20 | 6f 6e 63 65 20 63 72 65 |object, |once cre|
|000035e0| 61 74 65 64 2c 20 63 61 | 6e 6e 6f 74 20 62 65 20 |ated, ca|nnot be |
|000035f0| 6d 6f 64 69 66 69 65 64 | 3b 20 62 75 74 0a 69 74 |modified|; but.it|
|00003600| 20 69 73 20 65 61 73 79 | 20 65 6e 6f 75 67 68 20 | is easy| enough |
|00003610| 74 6f 20 75 6e 70 61 63 | 6b 20 69 74 20 61 6e 64 |to unpac|k it and|
|00003620| 20 63 72 65 61 74 65 20 | 61 20 6e 65 77 2c 20 6d | create |a new, m|
|00003630| 6f 64 69 66 69 65 64 20 | 74 75 70 6c 65 20 66 72 |odified |tuple fr|
|00003640| 6f 6d 0a 74 68 65 20 75 | 6e 70 61 63 6b 65 64 20 |om.the u|npacked |
|00003650| 69 74 65 6d 73 20 61 6e | 64 20 61 73 73 69 67 6e |items an|d assign|
|00003660| 20 74 68 69 73 20 74 6f | 20 74 68 65 20 76 61 72 | this to| the var|
|00003670| 69 61 62 6c 65 20 74 68 | 61 74 20 68 65 6c 64 20 |iable th|at held |
|00003680| 74 68 65 0a 6f 72 69 67 | 69 6e 61 6c 20 74 75 70 |the.orig|inal tup|
|00003690| 6c 65 20 6f 62 6a 65 63 | 74 20 28 77 68 69 63 68 |le objec|t (which|
|000036a0| 20 77 69 6c 6c 20 74 68 | 65 6e 20 62 65 20 67 61 | will th|en be ga|
|000036b0| 72 62 61 67 65 2d 63 6f | 6c 6c 65 63 74 65 64 29 |rbage-co|llected)|
|000036c0| 2e 0a 0a 7b 5c 65 6d 20 | 4c 69 73 74 73 7d 20 61 |...{\em |Lists} a|
|000036d0| 72 65 20 61 72 72 61 79 | 2d 6c 69 6b 65 20 6f 62 |re array|-like ob|
|000036e0| 6a 65 63 74 73 2e 20 20 | 4c 69 73 74 20 69 74 65 |jects. |List ite|
|000036f0| 6d 73 20 6d 61 79 20 62 | 65 20 61 72 62 69 74 72 |ms may b|e arbitr|
|00003700| 61 72 79 0a 6f 62 6a 65 | 63 74 73 20 61 6e 64 20 |ary.obje|cts and |
|00003710| 63 61 6e 20 62 65 20 61 | 63 63 65 73 73 65 64 20 |can be a|ccessed |
|00003720| 61 6e 64 20 63 68 61 6e | 67 65 64 20 75 73 69 6e |and chan|ged usin|
|00003730| 67 20 73 74 61 6e 64 61 | 72 64 20 73 75 62 73 63 |g standa|rd subsc|
|00003740| 72 69 70 74 69 6f 6e 0a | 6e 6f 74 61 74 69 6f 6e |ription.|notation|
|00003750| 2e 20 20 4c 69 73 74 73 | 20 73 75 70 70 6f 72 74 |. Lists| support|
|00003760| 20 69 74 65 6d 20 69 6e | 73 65 72 74 69 6f 6e 20 | item in|sertion |
|00003770| 61 6e 64 20 64 65 6c 65 | 74 69 6f 6e 2c 20 61 6e |and dele|tion, an|
|00003780| 64 20 63 61 6e 0a 74 68 | 65 72 65 66 6f 72 65 20 |d can.th|erefore |
|00003790| 62 65 20 75 73 65 64 20 | 61 73 20 71 75 65 75 65 |be used |as queue|
|000037a0| 73 2c 20 73 74 61 63 6b | 73 20 65 74 63 2e 3b 20 |s, stack|s etc.; |
|000037b0| 74 68 65 72 65 20 69 73 | 20 6e 6f 20 6c 69 6d 69 |there is| no limi|
|000037c0| 74 20 74 6f 20 74 68 65 | 69 72 0a 73 69 7a 65 2e |t to the|ir.size.|
|000037d0| 0a 0a 53 74 72 69 6e 67 | 73 2c 20 74 75 70 6c 65 |..String|s, tuple|
|000037e0| 73 20 61 6e 64 20 6c 69 | 73 74 73 20 74 6f 67 65 |s and li|sts toge|
|000037f0| 74 68 65 72 20 61 72 65 | 20 7b 5c 65 6d 20 73 65 |ther are| {\em se|
|00003800| 71 75 65 6e 63 65 7d 20 | 74 79 70 65 73 2e 20 20 |quence} |types. |
|00003810| 54 68 65 73 65 0a 73 68 | 61 72 65 20 61 20 63 6f |These.sh|are a co|
|00003820| 6d 6d 6f 6e 20 6e 6f 74 | 61 74 69 6f 6e 20 66 6f |mmon not|ation fo|
|00003830| 72 20 67 65 6e 65 72 69 | 63 20 6f 70 65 72 61 74 |r generi|c operat|
|00003840| 69 6f 6e 73 20 6f 6e 20 | 73 65 71 75 65 6e 63 65 |ions on |sequence|
|00003850| 73 20 73 75 63 68 20 61 | 73 0a 73 75 62 73 63 72 |s such a|s.subscr|
|00003860| 69 70 74 69 6f 6e 2c 20 | 63 6f 6e 63 61 74 65 6e |iption, |concaten|
|00003870| 61 74 69 6f 6e 2c 20 73 | 6c 69 63 69 6e 67 20 28 |ation, s|licing (|
|00003880| 74 61 6b 69 6e 67 20 73 | 75 62 73 65 71 75 65 6e |taking s|ubsequen|
|00003890| 63 65 73 29 20 61 6e 64 | 0a 6d 65 6d 62 65 72 73 |ces) and|.members|
|000038a0| 68 69 70 20 74 65 73 74 | 73 2e 20 20 41 73 20 69 |hip test|s. As i|
|000038b0| 6e 20 43 2c 20 73 75 62 | 73 63 72 69 70 74 73 20 |n C, sub|scripts |
|000038c0| 73 74 61 72 74 20 61 74 | 20 30 2e 0a 0a 7b 5c 65 |start at| 0...{\e|
|000038d0| 6d 20 44 69 63 74 69 6f | 6e 61 72 69 65 73 7d 20 |m Dictio|naries} |
|000038e0| 61 72 65 20 60 6d 61 70 | 70 69 6e 67 73 27 20 66 |are `map|pings' f|
|000038f0| 72 6f 6d 20 6f 6e 65 20 | 64 6f 6d 61 69 6e 20 74 |rom one |domain t|
|00003900| 6f 20 61 6e 6f 74 68 65 | 72 2e 20 20 54 68 65 0a |o anothe|r. The.|
|00003910| 62 61 73 69 63 20 6f 70 | 65 72 61 74 69 6f 6e 73 |basic op|erations|
|00003920| 20 6f 6e 20 64 69 63 74 | 69 6f 6e 61 72 69 65 73 | on dict|ionaries|
|00003930| 20 61 72 65 20 69 74 65 | 6d 20 69 6e 73 65 72 74 | are ite|m insert|
|00003940| 69 6f 6e 2c 20 65 78 74 | 72 61 63 74 69 6f 6e 20 |ion, ext|raction |
|00003950| 61 6e 64 0a 64 65 6c 65 | 74 69 6f 6e 2c 20 75 73 |and.dele|tion, us|
|00003960| 69 6e 67 20 73 75 62 73 | 63 72 69 70 74 20 6e 6f |ing subs|cript no|
|00003970| 74 61 74 69 6f 6e 20 77 | 69 74 68 20 74 68 65 20 |tation w|ith the |
|00003980| 6b 65 79 20 61 73 20 73 | 75 62 73 63 72 69 70 74 |key as s|ubscript|
|00003990| 2e 20 20 28 54 68 65 0a | 63 75 72 72 65 6e 74 20 |. (The.|current |
|000039a0| 69 6d 70 6c 65 6d 65 6e | 74 61 74 69 6f 6e 20 61 |implemen|tation a|
|000039b0| 6c 6c 6f 77 73 20 6f 6e | 6c 79 20 73 74 72 69 6e |llows on|ly strin|
|000039c0| 67 73 20 69 6e 20 74 68 | 65 20 6b 65 79 20 64 6f |gs in th|e key do|
|000039d0| 6d 61 69 6e 2c 20 62 75 | 74 20 61 0a 66 75 74 75 |main, bu|t a.futu|
|000039e0| 72 65 20 76 65 72 73 69 | 6f 6e 20 6f 66 20 74 68 |re versi|on of th|
|000039f0| 65 20 6c 61 6e 67 75 61 | 67 65 20 6d 61 79 20 72 |e langua|ge may r|
|00003a00| 65 6d 6f 76 65 20 74 68 | 69 73 20 72 65 73 74 72 |emove th|is restr|
|00003a10| 69 63 74 69 6f 6e 2e 29 | 0a 0a 5c 73 75 62 73 65 |iction.)|..\subse|
|00003a20| 63 74 69 6f 6e 7b 53 74 | 61 74 65 6d 65 6e 74 73 |ction{St|atements|
|00003a30| 7d 0a 0a 50 79 74 68 6f | 6e 20 68 61 73 20 76 61 |}..Pytho|n has va|
|00003a40| 72 69 6f 75 73 20 6b 69 | 6e 64 73 20 6f 66 20 73 |rious ki|nds of s|
|00003a50| 69 6d 70 6c 65 20 73 74 | 61 74 65 6d 65 6e 74 73 |imple st|atements|
|00003a60| 2c 20 73 75 63 68 20 61 | 73 20 61 73 73 69 67 6e |, such a|s assign|
|00003a70| 6d 65 6e 74 73 0a 61 6e | 64 20 7b 5c 74 74 20 70 |ments.an|d {\tt p|
|00003a80| 72 69 6e 74 7d 20 73 74 | 61 74 65 6d 65 6e 74 73 |rint} st|atements|
|00003a90| 2c 20 61 6e 64 20 73 65 | 76 65 72 61 6c 20 6b 69 |, and se|veral ki|
|00003aa0| 6e 64 73 20 6f 66 20 63 | 6f 6d 70 6f 75 6e 64 20 |nds of c|ompound |
|00003ab0| 73 74 61 74 65 6d 65 6e | 74 73 2c 0a 6c 69 6b 65 |statemen|ts,.like|
|00003ac0| 20 7b 5c 74 74 20 69 66 | 7d 20 61 6e 64 20 7b 5c | {\tt if|} and {\|
|00003ad0| 74 74 20 66 6f 72 7d 20 | 73 74 61 74 65 6d 65 6e |tt for} |statemen|
|00003ae0| 74 73 2e 20 20 46 6f 72 | 6d 61 6c 6c 79 2c 20 66 |ts. For|mally, f|
|00003af0| 75 6e 63 74 69 6f 6e 0a | 64 65 66 69 6e 69 74 69 |unction.|definiti|
|00003b00| 6f 6e 73 20 61 6e 64 20 | 7b 5c 74 74 20 69 6d 70 |ons and |{\tt imp|
|00003b10| 6f 72 74 7d 20 73 74 61 | 74 65 6d 65 6e 74 73 20 |ort} sta|tements |
|00003b20| 61 72 65 20 61 6c 73 6f | 20 73 74 61 74 65 6d 65 |are also| stateme|
|00003b30| 6e 74 73 2c 20 61 6e 64 | 20 74 68 65 72 65 0a 61 |nts, and| there.a|
|00003b40| 72 65 20 6e 6f 20 72 65 | 73 74 72 69 63 74 69 6f |re no re|strictio|
|00003b50| 6e 73 20 6f 6e 20 74 68 | 65 20 6f 72 64 65 72 69 |ns on th|e orderi|
|00003b60| 6e 67 20 6f 66 20 73 74 | 61 74 65 6d 65 6e 74 73 |ng of st|atements|
|00003b70| 20 6f 72 20 74 68 65 69 | 72 20 6e 65 73 74 69 6e | or thei|r nestin|
|00003b80| 67 3a 0a 7b 5c 74 74 20 | 69 6d 70 6f 72 74 7d 20 |g:.{\tt |import} |
|00003b90| 6d 61 79 20 62 65 20 75 | 73 65 64 20 69 6e 73 69 |may be u|sed insi|
|00003ba0| 64 65 20 61 20 66 75 6e | 63 74 69 6f 6e 2c 20 66 |de a fun|ction, f|
|00003bb0| 75 6e 63 74 69 6f 6e 73 | 20 6d 61 79 20 62 65 20 |unctions| may be |
|00003bc0| 64 65 66 69 6e 65 64 0a | 63 6f 6e 64 69 74 69 6f |defined.|conditio|
|00003bd0| 6e 61 6c 6c 79 20 75 73 | 69 6e 67 20 61 6e 20 7b |nally us|ing an {|
|00003be0| 5c 74 74 20 69 66 7d 20 | 73 74 61 74 65 6d 65 6e |\tt if} |statemen|
|00003bf0| 74 2c 20 65 74 63 2e 20 | 20 54 68 65 20 65 66 66 |t, etc. | The eff|
|00003c00| 65 63 74 20 6f 66 20 61 | 0a 64 65 63 6c 61 72 61 |ect of a|.declara|
|00003c10| 74 69 6f 6e 2d 6c 69 6b | 65 20 73 74 61 74 65 6d |tion-lik|e statem|
|00003c20| 65 6e 74 20 74 61 6b 65 | 73 20 70 6c 61 63 65 20 |ent take|s place |
|00003c30| 6f 6e 6c 79 20 77 68 65 | 6e 20 69 74 20 69 73 20 |only whe|n it is |
|00003c40| 65 78 65 63 75 74 65 64 | 2e 0a 0a 41 6c 6c 20 73 |executed|...All s|
|00003c50| 74 61 74 65 6d 65 6e 74 | 73 20 65 78 63 65 70 74 |tatement|s except|
|00003c60| 20 61 73 73 69 67 6e 6d | 65 6e 74 73 20 61 6e 64 | assignm|ents and|
|00003c70| 20 65 78 70 72 65 73 73 | 69 6f 6e 20 73 74 61 74 | express|ion stat|
|00003c80| 65 6d 65 6e 74 73 20 62 | 65 67 69 6e 20 77 69 74 |ements b|egin wit|
|00003c90| 68 0a 61 20 6b 65 79 77 | 6f 72 64 3a 20 74 68 69 |h.a keyw|ord: thi|
|00003ca0| 73 20 6d 61 6b 65 73 20 | 74 68 65 20 6c 61 6e 67 |s makes |the lang|
|00003cb0| 75 61 67 65 20 65 61 73 | 79 20 74 6f 20 70 61 72 |uage eas|y to par|
|00003cc0| 73 65 2e 20 20 41 6e 20 | 6f 76 65 72 76 69 65 77 |se. An |overview|
|00003cd0| 20 6f 66 20 74 68 65 0a | 6d 6f 73 74 20 63 6f 6d | of the.|most com|
|00003ce0| 6d 6f 6e 20 73 74 61 74 | 65 6d 65 6e 74 20 66 6f |mon stat|ement fo|
|00003cf0| 72 6d 73 20 69 6e 20 50 | 79 74 68 6f 6e 20 66 6f |rms in P|ython fo|
|00003d00| 6c 6c 6f 77 73 2e 0a 0a | 41 6e 20 7b 5c 65 6d 20 |llows...|An {\em |
|00003d10| 61 73 73 69 67 6e 6d 65 | 6e 74 7d 20 68 61 73 20 |assignme|nt} has |
|00003d20| 74 68 65 20 67 65 6e 65 | 72 61 6c 20 66 6f 72 6d |the gene|ral form|
|00003d30| 0a 5c 76 73 70 61 63 65 | 7b 5c 69 74 65 6d 73 65 |.\vspace|{\itemse|
|00003d40| 70 7d 0a 0a 5c 6e 6f 69 | 6e 64 65 6e 74 0a 7b 5c |p}..\noi|ndent.{\|
|00003d50| 65 6d 20 76 61 72 69 61 | 62 6c 65 20 24 3d 24 20 |em varia|ble $=$ |
|00003d60| 76 61 72 69 61 62 6c 65 | 20 24 3d 20 2e 2e 2e 20 |variable| $= ... |
|00003d70| 3d 24 20 76 61 72 69 61 | 62 6c 65 20 24 3d 24 20 |=$ varia|ble $=$ |
|00003d80| 65 78 70 72 65 73 73 69 | 6f 6e 7d 0a 5c 76 73 70 |expressi|on}.\vsp|
|00003d90| 61 63 65 7b 5c 69 74 65 | 6d 73 65 70 7d 0a 0a 49 |ace{\ite|msep}..I|
|00003da0| 74 20 61 73 73 69 67 6e | 73 20 74 68 65 20 76 61 |t assign|s the va|
|00003db0| 6c 75 65 20 6f 66 20 74 | 68 65 20 65 78 70 72 65 |lue of t|he expre|
|00003dc0| 73 73 69 6f 6e 20 74 6f | 20 61 6c 6c 20 6c 69 73 |ssion to| all lis|
|00003dd0| 74 65 64 20 76 61 72 69 | 61 62 6c 65 73 2e 20 20 |ted vari|ables. |
|00003de0| 28 41 73 0a 73 68 6f 77 | 6e 20 69 6e 20 74 68 65 |(As.show|n in the|
|00003df0| 20 73 65 63 74 69 6f 6e | 20 6f 6e 20 74 75 70 6c | section| on tupl|
|00003e00| 65 73 2c 20 76 61 72 69 | 61 62 6c 65 73 20 61 6e |es, vari|ables an|
|00003e10| 64 20 65 78 70 72 65 73 | 73 69 6f 6e 73 20 63 61 |d expres|sions ca|
|00003e20| 6e 20 69 6e 20 66 61 63 | 74 0a 62 65 20 63 6f 6d |n in fac|t.be com|
|00003e30| 6d 61 2d 73 65 70 61 72 | 61 74 65 64 20 6c 69 73 |ma-separ|ated lis|
|00003e40| 74 73 2e 29 20 20 54 68 | 65 20 61 73 73 69 67 6e |ts.) Th|e assign|
|00003e50| 6d 65 6e 74 20 6f 70 65 | 72 61 74 6f 72 20 69 73 |ment ope|rator is|
|00003e60| 20 6e 6f 74 20 61 6e 0a | 65 78 70 72 65 73 73 69 | not an.|expressi|
|00003e70| 6f 6e 20 6f 70 65 72 61 | 74 6f 72 3b 20 74 68 65 |on opera|tor; the|
|00003e80| 72 65 20 61 72 65 20 6e | 6f 20 68 6f 72 72 69 62 |re are n|o horrib|
|00003e90| 6c 65 20 74 68 69 6e 67 | 73 20 69 6e 20 50 79 74 |le thing|s in Pyt|
|00003ea0| 68 6f 6e 20 6c 69 6b 65 | 0a 5c 62 65 67 69 6e 7b |hon like|.\begin{|
|00003eb0| 76 65 72 62 61 74 69 6d | 7d 0a 77 68 69 6c 65 20 |verbatim|}.while |
|00003ec0| 28 70 20 3d 20 70 2d 3e | 6e 65 78 74 29 20 7b 20 |(p = p->|next) { |
|00003ed0| 2e 2e 2e 20 7d 0a 5c 65 | 6e 64 7b 76 65 72 62 61 |... }.\e|nd{verba|
|00003ee0| 74 69 6d 7d 0a 45 78 70 | 72 65 73 73 69 6f 6e 20 |tim}.Exp|ression |
|00003ef0| 73 79 6e 74 61 78 20 69 | 73 20 6d 6f 73 74 6c 79 |syntax i|s mostly|
|00003f00| 20 73 74 72 61 69 67 68 | 74 66 6f 72 77 61 72 64 | straigh|tforward|
|00003f10| 20 61 6e 64 20 77 69 6c | 6c 20 6e 6f 74 20 62 65 | and wil|l not be|
|00003f20| 20 65 78 70 6c 61 69 6e | 65 64 0a 69 6e 20 64 65 | explain|ed.in de|
|00003f30| 74 61 69 6c 20 68 65 72 | 65 2e 0a 0a 41 6e 20 7b |tail her|e...An {|
|00003f40| 5c 65 6d 20 65 78 70 72 | 65 73 73 69 6f 6e 20 73 |\em expr|ession s|
|00003f50| 74 61 74 65 6d 65 6e 74 | 7d 20 69 73 20 6a 75 73 |tatement|} is jus|
|00003f60| 74 20 61 6e 20 65 78 70 | 72 65 73 73 69 6f 6e 20 |t an exp|ression |
|00003f70| 6f 6e 20 61 20 6c 69 6e | 65 20 62 79 0a 69 74 73 |on a lin|e by.its|
|00003f80| 65 6c 66 2e 20 20 54 68 | 69 73 20 77 72 69 74 65 |elf. Th|is write|
|00003f90| 73 20 74 68 65 20 76 61 | 6c 75 65 20 6f 66 20 74 |s the va|lue of t|
|00003fa0| 68 65 20 65 78 70 72 65 | 73 73 69 6f 6e 20 74 6f |he expre|ssion to|
|00003fb0| 20 73 74 61 6e 64 61 72 | 64 20 6f 75 74 70 75 74 | standar|d output|
|00003fc0| 2c 0a 69 6e 20 61 20 73 | 75 69 74 61 62 6c 79 20 |,.in a s|uitably |
|00003fd0| 75 6e 61 6d 62 69 67 75 | 6f 75 73 20 77 61 79 2c |unambigu|ous way,|
|00003fe0| 20 75 6e 6c 65 73 73 20 | 69 74 20 69 73 20 61 20 | unless |it is a |
|00003ff0| 60 70 72 6f 63 65 64 75 | 72 65 20 63 61 6c 6c 27 |`procedu|re call'|
|00004000| 20 28 61 0a 66 75 6e 63 | 74 69 6f 6e 20 63 61 6c | (a.func|tion cal|
|00004010| 6c 20 74 68 61 74 20 72 | 65 74 75 72 6e 73 20 6e |l that r|eturns n|
|00004020| 6f 20 76 61 6c 75 65 29 | 2e 20 20 57 72 69 74 69 |o value)|. Writi|
|00004030| 6e 67 20 74 68 65 20 76 | 61 6c 75 65 20 69 73 20 |ng the v|alue is |
|00004040| 75 73 65 66 75 6c 0a 77 | 68 65 6e 20 50 79 74 68 |useful.w|hen Pyth|
|00004050| 6f 6e 20 69 73 20 75 73 | 65 64 20 69 6e 20 60 63 |on is us|ed in `c|
|00004060| 61 6c 63 75 6c 61 74 6f | 72 20 6d 6f 64 65 27 2c |alculato|r mode',|
|00004070| 20 61 6e 64 20 72 65 6d | 69 6e 64 73 20 74 68 65 | and rem|inds the|
|00004080| 20 70 72 6f 67 72 61 6d | 6d 65 72 0a 6e 6f 74 20 | program|mer.not |
|00004090| 74 6f 20 69 67 6e 6f 72 | 65 20 66 75 6e 63 74 69 |to ignor|e functi|
|000040a0| 6f 6e 20 72 65 73 75 6c | 74 73 2e 0a 0a 54 68 65 |on resul|ts...The|
|000040b0| 20 7b 5c 74 74 20 69 66 | 7d 20 73 74 61 74 65 6d | {\tt if|} statem|
|000040c0| 65 6e 74 20 61 6c 6c 6f | 77 73 20 63 6f 6e 64 69 |ent allo|ws condi|
|000040d0| 74 69 6f 6e 61 6c 20 65 | 78 65 63 75 74 69 6f 6e |tional e|xecution|
|000040e0| 2e 20 20 49 74 20 68 61 | 73 20 6f 70 74 69 6f 6e |. It ha|s option|
|000040f0| 61 6c 0a 7b 5c 74 74 20 | 65 6c 69 66 7d 20 61 6e |al.{\tt |elif} an|
|00004100| 64 20 7b 5c 74 74 20 65 | 6c 73 65 7d 20 70 61 72 |d {\tt e|lse} par|
|00004110| 74 73 3b 20 61 20 63 6f | 6e 73 74 72 75 63 74 20 |ts; a co|nstruct |
|00004120| 6c 69 6b 65 20 7b 5c 74 | 74 0a 69 66 2e 2e 2e 65 |like {\t|t.if...e|
|00004130| 6c 69 66 2e 2e 2e 65 6c | 69 66 2e 2e 2e 65 6c 69 |lif...el|if...eli|
|00004140| 66 2e 2e 2e 65 6c 73 65 | 7d 20 63 61 6e 20 62 65 |f...else|} can be|
|00004150| 20 75 73 65 64 20 74 6f | 20 63 6f 6d 70 65 6e 73 | used to| compens|
|00004160| 61 74 65 20 66 6f 72 20 | 74 68 65 0a 61 62 73 65 |ate for |the.abse|
|00004170| 6e 63 65 20 6f 66 20 61 | 20 7b 5c 65 6d 20 73 77 |nce of a| {\em sw|
|00004180| 69 74 63 68 7d 20 6f 72 | 20 7b 5c 65 6d 20 63 61 |itch} or| {\em ca|
|00004190| 73 65 7d 20 73 74 61 74 | 65 6d 65 6e 74 2e 0a 0a |se} stat|ement...|
|000041a0| 4c 6f 6f 70 69 6e 67 20 | 69 73 20 64 6f 6e 65 20 |Looping |is done |
|000041b0| 77 69 74 68 20 7b 5c 74 | 74 20 77 68 69 6c 65 7d |with {\t|t while}|
|000041c0| 20 61 6e 64 20 7b 5c 74 | 74 20 66 6f 72 7d 20 73 | and {\t|t for} s|
|000041d0| 74 61 74 65 6d 65 6e 74 | 73 2e 20 20 54 68 65 20 |tatement|s. The |
|000041e0| 6c 61 74 74 65 72 0a 28 | 64 65 6d 6f 6e 73 74 72 |latter.(|demonstr|
|000041f0| 61 74 65 64 20 69 6e 20 | 74 68 65 20 60 6c 73 27 |ated in |the `ls'|
|00004200| 20 65 78 61 6d 70 6c 65 | 20 65 61 72 6c 69 65 72 | example| earlier|
|00004210| 29 20 69 74 65 72 61 74 | 65 73 20 6f 76 65 72 20 |) iterat|es over |
|00004220| 74 68 65 20 65 6c 65 6d | 65 6e 74 73 0a 6f 66 20 |the elem|ents.of |
|00004230| 61 20 60 73 65 71 75 65 | 6e 63 65 27 20 28 73 65 |a `seque|nce' (se|
|00004240| 65 20 74 68 65 20 64 69 | 73 63 75 73 73 69 6f 6e |e the di|scussion|
|00004250| 20 6f 66 20 64 61 74 61 | 20 74 79 70 65 73 20 62 | of data| types b|
|00004260| 65 6c 6f 77 29 2e 20 20 | 49 74 20 69 73 0a 70 6f |elow). |It is.po|
|00004270| 73 73 69 62 6c 65 20 74 | 6f 20 74 65 72 6d 69 6e |ssible t|o termin|
|00004280| 61 74 65 20 61 20 6c 6f | 6f 70 20 77 69 74 68 20 |ate a lo|op with |
|00004290| 61 20 7b 5c 74 74 20 62 | 72 65 61 6b 7d 20 73 74 |a {\tt b|reak} st|
|000042a0| 61 74 65 6d 65 6e 74 20 | 6f 72 20 74 6f 20 73 74 |atement |or to st|
|000042b0| 61 72 74 0a 74 68 65 20 | 6e 65 78 74 20 69 74 65 |art.the |next ite|
|000042c0| 72 61 74 69 6f 6e 20 77 | 69 74 68 20 7b 5c 74 74 |ration w|ith {\tt|
|000042d0| 20 63 6f 6e 74 69 6e 75 | 65 7d 2e 20 20 42 6f 74 | continu|e}. Bot|
|000042e0| 68 20 6c 6f 6f 70 69 6e | 67 20 73 74 61 74 65 6d |h loopin|g statem|
|000042f0| 65 6e 74 73 20 68 61 76 | 65 0a 61 6e 20 6f 70 74 |ents hav|e.an opt|
|00004300| 69 6f 6e 61 6c 20 7b 5c | 74 74 20 65 6c 73 65 7d |ional {\|tt else}|
|00004310| 20 63 6c 61 75 73 65 20 | 77 68 69 63 68 20 69 73 | clause |which is|
|00004320| 20 65 78 65 63 75 74 65 | 64 20 61 66 74 65 72 20 | execute|d after |
|00004330| 74 68 65 20 6c 6f 6f 70 | 20 69 73 0a 74 65 72 6d |the loop| is.term|
|00004340| 69 6e 61 74 65 64 20 6e | 6f 72 6d 61 6c 6c 79 2c |inated n|ormally,|
|00004350| 20 62 75 74 20 73 6b 69 | 70 70 65 64 20 77 68 65 | but ski|pped whe|
|00004360| 6e 20 69 74 20 69 73 20 | 74 65 72 6d 69 6e 61 74 |n it is |terminat|
|00004370| 65 64 20 62 79 20 7b 5c | 74 74 20 62 72 65 61 6b |ed by {\|tt break|
|00004380| 7d 2e 0a 54 68 69 73 20 | 63 61 6e 20 62 65 20 68 |}..This |can be h|
|00004390| 61 6e 64 79 20 66 6f 72 | 20 73 65 61 72 63 68 65 |andy for| searche|
|000043a0| 73 2c 20 74 6f 20 68 61 | 6e 64 6c 65 20 74 68 65 |s, to ha|ndle the|
|000043b0| 20 63 61 73 65 20 74 68 | 61 74 20 74 68 65 20 69 | case th|at the i|
|000043c0| 74 65 6d 20 69 73 0a 6e | 6f 74 20 66 6f 75 6e 64 |tem is.n|ot found|
|000043d0| 2e 0a 0a 50 79 74 68 6f | 6e 27 73 20 7b 5c 65 6d |...Pytho|n's {\em|
|000043e0| 20 65 78 63 65 70 74 69 | 6f 6e 7d 20 6d 65 63 68 | excepti|on} mech|
|000043f0| 61 6e 69 73 6d 20 69 73 | 20 6d 6f 64 65 6c 6c 65 |anism is| modelle|
|00004400| 64 20 61 66 74 65 72 20 | 74 68 61 74 20 6f 66 20 |d after |that of |
|00004410| 4d 6f 64 75 6c 61 2d 33 | 2e 0a 45 78 63 65 70 74 |Modula-3|..Except|
|00004420| 69 6f 6e 73 20 61 72 65 | 20 72 61 69 73 65 64 20 |ions are| raised |
|00004430| 62 79 20 74 68 65 20 69 | 6e 74 65 72 70 72 65 74 |by the i|nterpret|
|00004440| 65 72 20 77 68 65 6e 20 | 61 6e 20 69 6c 6c 65 67 |er when |an illeg|
|00004450| 61 6c 20 6f 70 65 72 61 | 74 69 6f 6e 20 69 73 0a |al opera|tion is.|
|00004460| 74 72 69 65 64 2e 20 20 | 49 74 20 69 73 20 61 6c |tried. |It is al|
|00004470| 73 6f 20 70 6f 73 73 69 | 62 6c 65 20 74 6f 20 65 |so possi|ble to e|
|00004480| 78 70 6c 69 63 69 74 6c | 79 20 72 61 69 73 65 20 |xplicitl|y raise |
|00004490| 61 6e 20 65 78 63 65 70 | 74 69 6f 6e 20 77 69 74 |an excep|tion wit|
|000044a0| 68 20 74 68 65 0a 7b 5c | 74 74 20 72 61 69 73 65 |h the.{\|tt raise|
|000044b0| 7d 20 73 74 61 74 65 6d | 65 6e 74 3a 0a 5c 76 73 |} statem|ent:.\vs|
|000044c0| 70 61 63 65 7b 5c 69 74 | 65 6d 73 65 70 7d 0a 0a |pace{\it|emsep}..|
|000044d0| 5c 6e 6f 69 6e 64 65 6e | 74 0a 7b 5c 74 74 20 72 |\noinden|t.{\tt r|
|000044e0| 61 69 73 65 20 7b 5c 65 | 6d 20 65 78 70 72 65 73 |aise {\e|m expres|
|000044f0| 73 69 6f 6e 7d 2c 20 7b | 5c 65 6d 20 65 78 70 72 |sion}, {|\em expr|
|00004500| 65 73 73 69 6f 6e 7d 7d | 0a 5c 76 73 70 61 63 65 |ession}}|.\vspace|
|00004510| 7b 5c 69 74 65 6d 73 65 | 70 7d 0a 0a 54 68 65 20 |{\itemse|p}..The |
|00004520| 66 69 72 73 74 20 65 78 | 70 72 65 73 73 69 6f 6e |first ex|pression|
|00004530| 20 69 64 65 6e 74 69 66 | 69 65 73 20 77 68 69 63 | identif|ies whic|
|00004540| 68 20 65 78 63 65 70 74 | 69 6f 6e 20 73 68 6f 75 |h except|ion shou|
|00004550| 6c 64 20 62 65 20 72 61 | 69 73 65 64 3b 0a 74 68 |ld be ra|ised;.th|
|00004560| 65 72 65 20 61 72 65 20 | 73 65 76 65 72 61 6c 20 |ere are |several |
|00004570| 62 75 69 6c 74 2d 69 6e | 20 65 78 63 65 70 74 69 |built-in| excepti|
|00004580| 6f 6e 73 20 61 6e 64 20 | 74 68 65 20 75 73 65 72 |ons and |the user|
|00004590| 20 6d 61 79 20 64 65 66 | 69 6e 65 0a 61 64 64 69 | may def|ine.addi|
|000045a0| 74 69 6f 6e 61 6c 20 6f | 6e 65 73 2e 20 20 54 68 |tional o|nes. Th|
|000045b0| 65 20 73 65 63 6f 6e 64 | 2c 20 6f 70 74 69 6f 6e |e second|, option|
|000045c0| 61 6c 20 65 78 70 72 65 | 73 73 69 6f 6e 20 69 73 |al expre|ssion is|
|000045d0| 20 70 61 73 73 65 64 20 | 74 6f 20 74 68 65 0a 68 | passed |to the.h|
|000045e0| 61 6e 64 6c 65 72 2c 20 | 65 2e 67 2e 20 61 73 20 |andler, |e.g. as |
|000045f0| 61 20 64 65 74 61 69 6c | 65 64 20 65 72 72 6f 72 |a detail|ed error|
|00004600| 20 6d 65 73 73 61 67 65 | 2e 0a 0a 45 78 63 65 70 | message|...Excep|
|00004610| 74 69 6f 6e 73 20 6d 61 | 79 20 62 65 20 68 61 6e |tions ma|y be han|
|00004620| 64 6c 65 64 20 28 63 61 | 75 67 68 74 29 20 77 69 |dled (ca|ught) wi|
|00004630| 74 68 20 74 68 65 20 7b | 5c 74 74 20 74 72 79 7d |th the {|\tt try}|
|00004640| 20 73 74 61 74 65 6d 65 | 6e 74 2c 20 77 68 69 63 | stateme|nt, whic|
|00004650| 68 0a 68 61 73 20 74 68 | 65 20 66 6f 6c 6c 6f 77 |h.has th|e follow|
|00004660| 69 6e 67 20 67 65 6e 65 | 72 61 6c 20 66 6f 72 6d |ing gene|ral form|
|00004670| 3a 0a 5c 76 73 70 61 63 | 65 7b 5c 69 74 65 6d 73 |:.\vspac|e{\items|
|00004680| 65 70 7d 0a 0a 5c 6e 6f | 69 6e 64 65 6e 74 0a 7b |ep}..\no|indent.{|
|00004690| 5c 74 74 0a 5c 62 65 67 | 69 6e 7b 74 61 62 75 6c |\tt.\beg|in{tabul|
|000046a0| 61 72 7d 7b 6c 7d 0a 74 | 72 79 3a 20 7b 5c 65 6d |ar}{l}.t|ry: {\em|
|000046b0| 20 62 6c 6f 63 6b 7d 20 | 5c 5c 0a 65 78 63 65 70 | block} |\\.excep|
|000046c0| 74 20 7b 5c 65 6d 20 65 | 78 70 72 65 73 73 69 6f |t {\em e|xpressio|
|000046d0| 6e 7d 2c 20 7b 5c 65 6d | 20 76 61 72 69 61 62 6c |n}, {\em| variabl|
|000046e0| 65 7d 3a 20 7b 5c 65 6d | 20 62 6c 6f 63 6b 7d 20 |e}: {\em| block} |
|000046f0| 5c 5c 0a 65 78 63 65 70 | 74 20 7b 5c 65 6d 20 65 |\\.excep|t {\em e|
|00004700| 78 70 72 65 73 73 69 6f | 6e 7d 2c 20 7b 5c 65 6d |xpressio|n}, {\em|
|00004710| 20 76 61 72 69 61 62 6c | 65 7d 3a 20 7b 5c 65 6d | variabl|e}: {\em|
|00004720| 20 62 6c 6f 63 6b 7d 20 | 5c 5c 0a 2e 2e 2e 20 5c | block} |\\.... \|
|00004730| 5c 0a 65 78 63 65 70 74 | 3a 20 7b 5c 65 6d 20 62 |\.except|: {\em b|
|00004740| 6c 6f 63 6b 7d 0a 5c 65 | 6e 64 7b 74 61 62 75 6c |lock}.\e|nd{tabul|
|00004750| 61 72 7d 0a 7d 0a 5c 76 | 73 70 61 63 65 7b 5c 69 |ar}.}.\v|space{\i|
|00004760| 74 65 6d 73 65 70 7d 0a | 0a 57 68 65 6e 20 61 6e |temsep}.|.When an|
|00004770| 20 65 78 63 65 70 74 69 | 6f 6e 20 69 73 20 72 61 | excepti|on is ra|
|00004780| 69 73 65 64 20 64 75 72 | 69 6e 67 20 65 78 65 63 |ised dur|ing exec|
|00004790| 75 74 69 6f 6e 20 6f 66 | 20 74 68 65 20 66 69 72 |ution of| the fir|
|000047a0| 73 74 20 62 6c 6f 63 6b | 2c 20 61 0a 73 65 61 72 |st block|, a.sear|
|000047b0| 63 68 20 66 6f 72 20 61 | 6e 20 65 78 63 65 70 74 |ch for a|n except|
|000047c0| 69 6f 6e 20 68 61 6e 64 | 6c 65 72 20 73 74 61 72 |ion hand|ler star|
|000047d0| 74 73 2e 20 20 54 68 65 | 20 66 69 72 73 74 20 7b |ts. The| first {|
|000047e0| 5c 74 74 20 65 78 63 65 | 70 74 7d 20 63 6c 61 75 |\tt exce|pt} clau|
|000047f0| 73 65 0a 77 68 6f 73 65 | 20 7b 5c 65 6d 20 65 78 |se.whose| {\em ex|
|00004800| 70 72 65 73 73 69 6f 6e | 7d 20 6d 61 74 63 68 65 |pression|} matche|
|00004810| 73 20 74 68 65 20 65 78 | 63 65 70 74 69 6f 6e 20 |s the ex|ception |
|00004820| 69 73 20 65 78 65 63 75 | 74 65 64 2e 20 20 54 68 |is execu|ted. Th|
|00004830| 65 0a 65 78 70 72 65 73 | 73 69 6f 6e 20 6d 61 79 |e.expres|sion may|
|00004840| 20 73 70 65 63 69 66 79 | 20 61 20 6c 69 73 74 20 | specify| a list |
|00004850| 6f 66 20 65 78 63 65 70 | 74 69 6f 6e 73 20 74 6f |of excep|tions to|
|00004860| 20 6d 61 74 63 68 20 61 | 67 61 69 6e 73 74 2e 20 | match a|gainst. |
|00004870| 20 41 0a 68 61 6e 64 6c | 65 72 20 77 69 74 68 6f | A.handl|er witho|
|00004880| 75 74 20 61 6e 20 65 78 | 70 72 65 73 73 69 6f 6e |ut an ex|pression|
|00004890| 20 73 65 72 76 65 73 20 | 61 73 20 61 20 60 63 61 | serves |as a `ca|
|000048a0| 74 63 68 2d 61 6c 6c 27 | 2e 20 20 49 66 20 74 68 |tch-all'|. If th|
|000048b0| 65 72 65 20 69 73 20 6e | 6f 0a 6d 61 74 63 68 2c |ere is n|o.match,|
|000048c0| 20 74 68 65 20 73 65 61 | 72 63 68 20 66 6f 72 20 | the sea|rch for |
|000048d0| 61 20 68 61 6e 64 6c 65 | 72 20 63 6f 6e 74 69 6e |a handle|r contin|
|000048e0| 75 65 73 20 77 69 74 68 | 20 6f 75 74 65 72 20 7b |ues with| outer {|
|000048f0| 5c 74 74 20 74 72 79 7d | 0a 73 74 61 74 65 6d 65 |\tt try}|.stateme|
|00004900| 6e 74 73 3b 20 69 66 20 | 6e 6f 20 6d 61 74 63 68 |nts; if |no match|
|00004910| 20 69 73 20 66 6f 75 6e | 64 20 6f 6e 20 74 68 65 | is foun|d on the|
|00004920| 20 65 6e 74 69 72 65 20 | 69 6e 76 6f 63 61 74 69 | entire |invocati|
|00004930| 6f 6e 20 73 74 61 63 6b | 2c 20 61 6e 0a 65 72 72 |on stack|, an.err|
|00004940| 6f 72 20 6d 65 73 73 61 | 67 65 20 61 6e 64 20 73 |or messa|ge and s|
|00004950| 74 61 63 6b 20 74 72 61 | 63 65 20 61 72 65 20 70 |tack tra|ce are p|
|00004960| 72 69 6e 74 65 64 2c 20 | 61 6e 64 20 74 68 65 20 |rinted, |and the |
|00004970| 70 72 6f 67 72 61 6d 20 | 69 73 0a 74 65 72 6d 69 |program |is.termi|
|00004980| 6e 61 74 65 64 20 28 69 | 6e 74 65 72 61 63 74 69 |nated (i|nteracti|
|00004990| 76 65 6c 79 2c 20 74 68 | 65 20 69 6e 74 65 72 70 |vely, th|e interp|
|000049a0| 72 65 74 65 72 20 72 65 | 74 75 72 6e 73 20 74 6f |reter re|turns to|
|000049b0| 20 69 74 73 20 6d 61 69 | 6e 20 6c 6f 6f 70 29 2e | its mai|n loop).|
|000049c0| 0a 0a 4e 6f 74 65 20 74 | 68 61 74 20 74 68 65 20 |..Note t|hat the |
|000049d0| 66 6f 72 6d 20 6f 66 20 | 74 68 65 20 7b 5c 74 74 |form of |the {\tt|
|000049e0| 20 65 78 63 65 70 74 7d | 20 63 6c 61 75 73 65 73 | except}| clauses|
|000049f0| 20 65 6e 63 6f 75 72 61 | 67 65 73 20 61 20 73 74 | encoura|ges a st|
|00004a00| 79 6c 65 20 6f 66 0a 70 | 72 6f 67 72 61 6d 6d 69 |yle of.p|rogrammi|
|00004a10| 6e 67 20 77 68 65 72 65 | 62 79 20 6f 6e 6c 79 20 |ng where|by only |
|00004a20| 73 65 6c 65 63 74 65 64 | 20 65 78 63 65 70 74 69 |selected| excepti|
|00004a30| 6f 6e 73 20 61 72 65 20 | 63 61 75 67 68 74 2c 20 |ons are |caught, |
|00004a40| 70 61 73 73 69 6e 67 0a | 75 6e 61 6e 74 69 63 69 |passing.|unantici|
|00004a50| 70 61 74 65 64 20 65 78 | 63 65 70 74 69 6f 6e 73 |pated ex|ceptions|
|00004a60| 20 6f 6e 20 74 6f 20 74 | 68 65 20 63 61 6c 6c 65 | on to t|he calle|
|00004a70| 72 20 61 6e 64 20 75 6c | 74 69 6d 61 74 65 6c 79 |r and ul|timately|
|00004a80| 20 74 6f 20 74 68 65 20 | 75 73 65 72 2e 0a 54 68 | to the |user..Th|
|00004a90| 69 73 20 69 73 20 70 72 | 65 66 65 72 61 62 6c 65 |is is pr|eferable|
|00004aa0| 20 6f 76 65 72 20 61 20 | 73 69 6d 70 6c 65 72 20 | over a |simpler |
|00004ab0| 60 63 61 74 63 68 2d 61 | 6c 6c 27 20 65 72 72 6f |`catch-a|ll' erro|
|00004ac0| 72 20 68 61 6e 64 6c 69 | 6e 67 0a 6d 65 63 68 61 |r handli|ng.mecha|
|00004ad0| 6e 69 73 6d 2c 20 77 68 | 65 72 65 20 61 20 73 69 |nism, wh|ere a si|
|00004ae0| 6d 70 6c 69 73 74 69 63 | 20 68 61 6e 64 6c 65 72 |mplistic| handler|
|00004af0| 20 69 6e 74 65 6e 64 65 | 64 20 74 6f 20 63 61 74 | intende|d to cat|
|00004b00| 63 68 20 61 20 73 69 6e | 67 6c 65 20 74 79 70 65 |ch a sin|gle type|
|00004b10| 0a 6f 66 20 65 72 72 6f | 72 20 6c 69 6b 65 20 60 |.of erro|r like `|
|00004b20| 66 69 6c 65 20 6e 6f 74 | 20 66 6f 75 6e 64 27 20 |file not| found' |
|00004b30| 63 61 6e 20 65 61 73 69 | 6c 79 20 6d 61 73 6b 20 |can easi|ly mask |
|00004b40| 67 65 6e 75 69 6e 65 20 | 70 72 6f 67 72 61 6d 6d |genuine |programm|
|00004b50| 69 6e 67 0a 65 72 72 6f | 72 73 20 2d 2d 2d 20 65 |ing.erro|rs --- e|
|00004b60| 73 70 65 63 69 61 6c 6c | 79 20 69 6e 20 61 20 6c |speciall|y in a l|
|00004b70| 61 6e 67 75 61 67 65 20 | 6c 69 6b 65 20 50 79 74 |anguage |like Pyt|
|00004b80| 68 6f 6e 20 77 68 69 63 | 68 20 72 65 6c 69 65 73 |hon whic|h relies|
|00004b90| 20 73 74 72 6f 6e 67 6c | 79 0a 6f 6e 20 72 75 6e | strongl|y.on run|
|00004ba0| 2d 74 69 6d 65 20 63 68 | 65 63 6b 69 6e 67 20 61 |-time ch|ecking a|
|00004bb0| 6e 64 20 61 6c 6c 6f 77 | 73 20 74 68 65 20 63 61 |nd allow|s the ca|
|00004bc0| 74 63 68 69 6e 67 20 6f | 66 20 61 6c 6d 6f 73 74 |tching o|f almost|
|00004bd0| 20 61 6e 79 20 74 79 70 | 65 20 6f 66 0a 65 72 72 | any typ|e of.err|
|00004be0| 6f 72 2e 0a 0a 4f 74 68 | 65 72 20 63 6f 6d 6d 6f |or...Oth|er commo|
|00004bf0| 6e 20 73 74 61 74 65 6d | 65 6e 74 20 66 6f 72 6d |n statem|ent form|
|00004c00| 73 2c 20 77 68 69 63 68 | 20 77 65 20 68 61 76 65 |s, which| we have|
|00004c10| 20 61 6c 72 65 61 64 79 | 20 65 6e 63 6f 75 6e 74 | already| encount|
|00004c20| 65 72 65 64 2c 20 61 72 | 65 0a 66 75 6e 63 74 69 |ered, ar|e.functi|
|00004c30| 6f 6e 20 64 65 66 69 6e | 69 74 69 6f 6e 73 2c 20 |on defin|itions, |
|00004c40| 7b 5c 74 74 20 69 6d 70 | 6f 72 74 7d 20 73 74 61 |{\tt imp|ort} sta|
|00004c50| 74 65 6d 65 6e 74 73 20 | 61 6e 64 20 7b 5c 74 74 |tements |and {\tt|
|00004c60| 20 70 72 69 6e 74 7d 0a | 73 74 61 74 65 6d 65 6e | print}.|statemen|
|00004c70| 74 73 2e 20 20 54 68 65 | 72 65 20 69 73 20 61 6c |ts. The|re is al|
|00004c80| 73 6f 20 61 20 7b 5c 74 | 74 20 64 65 6c 7d 20 73 |so a {\t|t del} s|
|00004c90| 74 61 74 65 6d 65 6e 74 | 20 74 6f 20 64 65 6c 65 |tatement| to dele|
|00004ca0| 74 65 20 6f 6e 65 20 6f | 72 20 6d 6f 72 65 0a 76 |te one o|r more.v|
|00004cb0| 61 72 69 61 62 6c 65 73 | 2c 20 61 20 7b 5c 74 74 |ariables|, a {\tt|
|00004cc0| 20 72 65 74 75 72 6e 7d | 20 73 74 61 74 65 6d 65 | return}| stateme|
|00004cd0| 6e 74 20 74 6f 20 72 65 | 74 75 72 6e 20 66 72 6f |nt to re|turn fro|
|00004ce0| 6d 20 61 20 66 75 6e 63 | 74 69 6f 6e 2c 20 61 6e |m a func|tion, an|
|00004cf0| 64 20 61 0a 7b 5c 74 74 | 20 67 6c 6f 62 61 6c 7d |d a.{\tt| global}|
|00004d00| 20 73 74 61 74 65 6d 65 | 6e 74 20 74 6f 20 61 6c | stateme|nt to al|
|00004d10| 6c 6f 77 20 61 73 73 69 | 67 6e 6d 65 6e 74 73 20 |low assi|gnments |
|00004d20| 74 6f 20 67 6c 6f 62 61 | 6c 20 76 61 72 69 61 62 |to globa|l variab|
|00004d30| 6c 65 73 2e 0a 46 69 6e | 61 6c 6c 79 2c 20 74 68 |les..Fin|ally, th|
|00004d40| 65 20 7b 5c 74 74 20 70 | 61 73 73 7d 20 73 74 61 |e {\tt p|ass} sta|
|00004d50| 74 65 6d 65 6e 74 20 69 | 73 20 61 20 6e 6f 2d 6f |tement i|s a no-o|
|00004d60| 70 2e 0a 0a 5c 73 75 62 | 73 65 63 74 69 6f 6e 7b |p...\sub|section{|
|00004d70| 45 78 65 63 75 74 69 6f | 6e 20 4d 6f 64 65 6c 7d |Executio|n Model}|
|00004d80| 0a 0a 41 20 50 79 74 68 | 6f 6e 20 70 72 6f 67 72 |..A Pyth|on progr|
|00004d90| 61 6d 20 69 73 20 65 78 | 65 63 75 74 65 64 20 62 |am is ex|ecuted b|
|00004da0| 79 20 61 20 73 74 61 63 | 6b 2d 62 61 73 65 64 20 |y a stac|k-based |
|00004db0| 69 6e 74 65 72 70 72 65 | 74 65 72 2e 0a 0a 57 68 |interpre|ter...Wh|
|00004dc0| 65 6e 20 61 20 66 75 6e | 63 74 69 6f 6e 20 69 73 |en a fun|ction is|
|00004dd0| 20 63 61 6c 6c 65 64 2c | 20 61 20 6e 65 77 20 60 | called,| a new `|
|00004de0| 65 78 65 63 75 74 69 6f | 6e 20 65 6e 76 69 72 6f |executio|n enviro|
|00004df0| 6e 6d 65 6e 74 27 20 66 | 6f 72 20 69 74 20 69 73 |nment' f|or it is|
|00004e00| 0a 70 75 73 68 65 64 20 | 6f 6e 74 6f 20 74 68 65 |.pushed |onto the|
|00004e10| 20 73 74 61 63 6b 2e 20 | 20 41 6e 20 65 78 65 63 | stack. | An exec|
|00004e20| 75 74 69 6f 6e 20 65 6e | 76 69 72 6f 6e 6d 65 6e |ution en|vironmen|
|00004e30| 74 20 63 6f 6e 74 61 69 | 6e 73 20 28 61 6d 6f 6e |t contai|ns (amon|
|00004e40| 67 20 6f 74 68 65 72 0a | 64 61 74 61 29 20 70 6f |g other.|data) po|
|00004e50| 69 6e 74 65 72 73 20 74 | 6f 20 74 77 6f 20 60 73 |inters t|o two `s|
|00004e60| 79 6d 62 6f 6c 20 74 61 | 62 6c 65 73 27 20 74 68 |ymbol ta|bles' th|
|00004e70| 61 74 20 61 72 65 20 75 | 73 65 64 20 74 6f 20 68 |at are u|sed to h|
|00004e80| 6f 6c 64 20 76 61 72 69 | 61 62 6c 65 73 3a 0a 74 |old vari|ables:.t|
|00004e90| 68 65 20 6c 6f 63 61 6c | 20 61 6e 64 20 74 68 65 |he local| and the|
|00004ea0| 20 67 6c 6f 62 61 6c 20 | 73 79 6d 62 6f 6c 20 74 | global |symbol t|
|00004eb0| 61 62 6c 65 2e 20 20 54 | 68 65 20 6c 6f 63 61 6c |able. T|he local|
|00004ec0| 20 73 79 6d 62 6f 6c 20 | 74 61 62 6c 65 0a 63 6f | symbol |table.co|
|00004ed0| 6e 74 61 69 6e 73 20 6c | 6f 63 61 6c 20 76 61 72 |ntains l|ocal var|
|00004ee0| 69 61 62 6c 65 73 20 6f | 66 20 74 68 65 20 63 75 |iables o|f the cu|
|00004ef0| 72 72 65 6e 74 20 66 75 | 6e 63 74 69 6f 6e 20 69 |rrent fu|nction i|
|00004f00| 6e 76 6f 63 61 74 69 6f | 6e 20 28 69 6e 63 6c 75 |nvocatio|n (inclu|
|00004f10| 64 69 6e 67 0a 74 68 65 | 20 66 75 6e 63 74 69 6f |ding.the| functio|
|00004f20| 6e 20 61 72 67 75 6d 65 | 6e 74 73 29 3b 20 74 68 |n argume|nts); th|
|00004f30| 65 20 67 6c 6f 62 61 6c | 20 73 79 6d 62 6f 6c 20 |e global| symbol |
|00004f40| 74 61 62 6c 65 20 63 6f | 6e 74 61 69 6e 73 20 76 |table co|ntains v|
|00004f50| 61 72 69 61 62 6c 65 73 | 0a 64 65 66 69 6e 65 64 |ariables|.defined|
|00004f60| 20 69 6e 20 74 68 65 20 | 6d 6f 64 75 6c 65 20 63 | in the |module c|
|00004f70| 6f 6e 74 61 69 6e 69 6e | 67 20 74 68 65 20 63 75 |ontainin|g the cu|
|00004f80| 72 72 65 6e 74 20 66 75 | 6e 63 74 69 6f 6e 2e 0a |rrent fu|nction..|
|00004f90| 0a 54 68 65 20 60 67 6c | 6f 62 61 6c 27 20 73 79 |.The `gl|obal' sy|
|00004fa0| 6d 62 6f 6c 20 74 61 62 | 6c 65 20 69 73 20 74 68 |mbol tab|le is th|
|00004fb0| 75 73 20 6f 6e 6c 79 20 | 67 6c 6f 62 61 6c 20 77 |us only |global w|
|00004fc0| 69 74 68 20 72 65 73 70 | 65 63 74 20 74 6f 20 74 |ith resp|ect to t|
|00004fd0| 68 65 0a 63 75 72 72 65 | 6e 74 20 66 75 6e 63 74 |he.curre|nt funct|
|00004fe0| 69 6f 6e 2e 20 20 54 68 | 65 72 65 20 61 72 65 20 |ion. Th|ere are |
|00004ff0| 6e 6f 20 73 79 73 74 65 | 6d 2d 77 69 64 65 20 67 |no syste|m-wide g|
|00005000| 6c 6f 62 61 6c 20 76 61 | 72 69 61 62 6c 65 73 3b |lobal va|riables;|
|00005010| 20 75 73 69 6e 67 0a 74 | 68 65 20 7b 5c 74 74 20 | using.t|he {\tt |
|00005020| 69 6d 70 6f 72 74 7d 20 | 73 74 61 74 65 6d 65 6e |import} |statemen|
|00005030| 74 20 69 74 20 69 73 20 | 65 61 73 79 20 65 6e 6f |t it is |easy eno|
|00005040| 75 67 68 20 74 6f 20 72 | 65 66 65 72 65 6e 63 65 |ugh to r|eference|
|00005050| 20 76 61 72 69 61 62 6c | 65 73 0a 74 68 61 74 20 | variabl|es.that |
|00005060| 61 72 65 20 64 65 66 69 | 6e 65 64 20 69 6e 20 6f |are defi|ned in o|
|00005070| 74 68 65 72 20 6d 6f 64 | 75 6c 65 73 2e 20 20 41 |ther mod|ules. A|
|00005080| 20 73 79 73 74 65 6d 2d | 77 69 64 65 20 72 65 61 | system-|wide rea|
|00005090| 64 2d 6f 6e 6c 79 20 73 | 79 6d 62 6f 6c 0a 74 61 |d-only s|ymbol.ta|
|000050a0| 62 6c 65 20 69 73 20 75 | 73 65 64 20 66 6f 72 20 |ble is u|sed for |
|000050b0| 62 75 69 6c 74 2d 69 6e | 20 66 75 6e 63 74 69 6f |built-in| functio|
|000050c0| 6e 73 20 61 6e 64 20 63 | 6f 6e 73 74 61 6e 74 73 |ns and c|onstants|
|000050d0| 20 74 68 6f 75 67 68 2e | 0a 0a 4f 6e 20 61 73 73 | though.|..On ass|
|000050e0| 69 67 6e 6d 65 6e 74 20 | 74 6f 20 61 20 76 61 72 |ignment |to a var|
|000050f0| 69 61 62 6c 65 2c 20 62 | 79 20 64 65 66 61 75 6c |iable, b|y defaul|
|00005100| 74 20 61 6e 20 65 6e 74 | 72 79 20 66 6f 72 20 69 |t an ent|ry for i|
|00005110| 74 20 69 73 20 6d 61 64 | 65 20 69 6e 20 74 68 65 |t is mad|e in the|
|00005120| 0a 6c 6f 63 61 6c 20 73 | 79 6d 62 6f 6c 20 74 61 |.local s|ymbol ta|
|00005130| 62 6c 65 20 6f 66 20 74 | 68 65 20 63 75 72 72 65 |ble of t|he curre|
|00005140| 6e 74 20 65 78 65 63 75 | 74 69 6f 6e 20 65 6e 76 |nt execu|tion env|
|00005150| 69 72 6f 6e 6d 65 6e 74 | 2e 20 20 54 68 65 20 7b |ironment|. The {|
|00005160| 5c 74 74 0a 67 6c 6f 62 | 61 6c 7d 20 63 6f 6d 6d |\tt.glob|al} comm|
|00005170| 61 6e 64 20 63 61 6e 20 | 6f 76 65 72 72 69 64 65 |and can |override|
|00005180| 20 74 68 69 73 20 28 69 | 74 20 69 73 20 6e 6f 74 | this (i|t is not|
|00005190| 20 65 6e 6f 75 67 68 20 | 74 68 61 74 20 61 20 67 | enough |that a g|
|000051a0| 6c 6f 62 61 6c 0a 76 61 | 72 69 61 62 6c 65 20 62 |lobal.va|riable b|
|000051b0| 79 20 74 68 65 20 73 61 | 6d 65 20 6e 61 6d 65 20 |y the sa|me name |
|000051c0| 61 6c 72 65 61 64 79 20 | 65 78 69 73 74 73 29 2e |already |exists).|
|000051d0| 20 20 57 68 65 6e 20 61 | 20 76 61 72 69 61 62 6c | When a| variabl|
|000051e0| 65 27 73 20 76 61 6c 75 | 65 20 69 73 0a 6e 65 65 |e's valu|e is.nee|
|000051f0| 64 65 64 2c 20 69 74 20 | 69 73 20 73 65 61 72 63 |ded, it |is searc|
|00005200| 68 65 64 20 66 69 72 73 | 74 20 69 6e 20 74 68 65 |hed firs|t in the|
|00005210| 20 6c 6f 63 61 6c 20 73 | 79 6d 62 6f 6c 20 74 61 | local s|ymbol ta|
|00005220| 62 6c 65 2c 20 74 68 65 | 6e 20 69 6e 20 74 68 65 |ble, the|n in the|
|00005230| 0a 67 6c 6f 62 61 6c 20 | 6f 6e 65 2c 20 61 6e 64 |.global |one, and|
|00005240| 20 66 69 6e 61 6c 6c 79 | 20 69 6e 20 74 68 65 20 | finally| in the |
|00005250| 73 79 6d 62 6f 6c 20 74 | 61 62 6c 65 20 63 6f 6e |symbol t|able con|
|00005260| 74 61 69 6e 69 6e 67 20 | 62 75 69 6c 74 2d 69 6e |taining |built-in|
|00005270| 0a 66 75 6e 63 74 69 6f | 6e 73 20 61 6e 64 20 63 |.functio|ns and c|
|00005280| 6f 6e 73 74 61 6e 74 73 | 2e 0a 0a 54 68 65 20 74 |onstants|...The t|
|00005290| 65 72 6d 20 60 76 61 72 | 69 61 62 6c 65 27 20 69 |erm `var|iable' i|
|000052a0| 6e 20 74 68 69 73 20 63 | 6f 6e 74 65 78 74 20 72 |n this c|ontext r|
|000052b0| 65 66 65 72 73 20 74 6f | 20 61 6e 79 20 6e 61 6d |efers to| any nam|
|000052c0| 65 3a 20 66 75 6e 63 74 | 69 6f 6e 73 20 61 6e 64 |e: funct|ions and|
|000052d0| 0a 69 6d 70 6f 72 74 65 | 64 20 6d 6f 64 75 6c 65 |.importe|d module|
|000052e0| 73 20 61 72 65 20 73 65 | 61 72 63 68 65 64 20 69 |s are se|arched i|
|000052f0| 6e 20 65 78 61 63 74 6c | 79 20 74 68 65 20 73 61 |n exactl|y the sa|
|00005300| 6d 65 20 77 61 79 2e 20 | 20 0a 0a 4e 61 6d 65 73 |me way. | ..Names|
|00005310| 20 64 65 66 69 6e 65 64 | 20 69 6e 20 61 20 6d 6f | defined| in a mo|
|00005320| 64 75 6c 65 27 73 20 73 | 79 6d 62 6f 6c 20 74 61 |dule's s|ymbol ta|
|00005330| 62 6c 65 20 73 75 72 76 | 69 76 65 20 75 6e 74 69 |ble surv|ive unti|
|00005340| 6c 20 74 68 65 20 65 6e | 64 20 6f 66 20 74 68 65 |l the en|d of the|
|00005350| 0a 70 72 6f 67 72 61 6d | 2e 20 20 54 68 69 73 20 |.program|. This |
|00005360| 61 70 70 72 6f 78 69 6d | 61 74 65 73 20 74 68 65 |approxim|ates the|
|00005370| 20 73 65 6d 61 6e 74 69 | 63 73 20 6f 66 20 66 69 | semanti|cs of fi|
|00005380| 6c 65 2d 73 74 61 74 69 | 63 20 67 6c 6f 62 61 6c |le-stati|c global|
|00005390| 0a 76 61 72 69 61 62 6c | 65 73 20 69 6e 20 43 20 |.variabl|es in C |
|000053a0| 6f 72 20 6d 6f 64 75 6c | 65 20 76 61 72 69 61 62 |or modul|e variab|
|000053b0| 6c 65 73 20 69 6e 20 4d | 6f 64 75 6c 61 2d 33 2e |les in M|odula-3.|
|000053c0| 20 20 41 20 6d 6f 64 75 | 6c 65 20 69 73 0a 69 6e | A modu|le is.in|
|000053d0| 69 74 69 61 6c 69 7a 65 | 64 20 74 68 65 20 66 69 |itialize|d the fi|
|000053e0| 72 73 74 20 74 69 6d 65 | 20 69 74 20 69 73 20 69 |rst time| it is i|
|000053f0| 6d 70 6f 72 74 65 64 2c | 20 62 79 20 65 78 65 63 |mported,| by exec|
|00005400| 75 74 69 6e 67 20 74 68 | 65 20 74 65 78 74 20 6f |uting th|e text o|
|00005410| 66 0a 74 68 65 20 6d 6f | 64 75 6c 65 20 61 73 20 |f.the mo|dule as |
|00005420| 61 20 70 61 72 61 6d 65 | 74 65 72 6c 65 73 73 20 |a parame|terless |
|00005430| 66 75 6e 63 74 69 6f 6e | 20 77 68 6f 73 65 20 6c |function| whose l|
|00005440| 6f 63 61 6c 20 61 6e 64 | 20 67 6c 6f 62 61 6c 20 |ocal and| global |
|00005450| 73 79 6d 62 6f 6c 0a 74 | 61 62 6c 65 73 20 61 72 |symbol.t|ables ar|
|00005460| 65 20 74 68 65 20 73 61 | 6d 65 2c 20 73 6f 20 6e |e the sa|me, so n|
|00005470| 61 6d 65 73 20 61 72 65 | 20 64 65 66 69 6e 65 64 |ames are| defined|
|00005480| 20 69 6e 20 6d 6f 64 75 | 6c 65 27 73 20 73 79 6d | in modu|le's sym|
|00005490| 62 6f 6c 20 74 61 62 6c | 65 2e 0a 28 4d 6f 64 75 |bol tabl|e..(Modu|
|000054a0| 6c 65 73 20 69 6d 70 6c | 65 6d 65 6e 74 65 64 20 |les impl|emented |
|000054b0| 69 6e 20 43 20 68 61 76 | 65 20 61 6e 6f 74 68 65 |in C hav|e anothe|
|000054c0| 72 20 77 61 79 20 74 6f | 20 64 65 66 69 6e 65 20 |r way to| define |
|000054d0| 73 79 6d 62 6f 6c 73 2e | 29 0a 0a 41 20 50 79 74 |symbols.|)..A Pyt|
|000054e0| 68 6f 6e 20 6d 61 69 6e | 20 70 72 6f 67 72 61 6d |hon main| program|
|000054f0| 20 69 73 20 72 65 61 64 | 20 66 72 6f 6d 20 73 74 | is read| from st|
|00005500| 61 6e 64 61 72 64 20 69 | 6e 70 75 74 20 6f 72 20 |andard i|nput or |
|00005510| 66 72 6f 6d 20 61 20 73 | 63 72 69 70 74 0a 66 69 |from a s|cript.fi|
|00005520| 6c 65 20 70 61 73 73 65 | 64 20 61 73 20 61 6e 20 |le passe|d as an |
|00005530| 61 72 67 75 6d 65 6e 74 | 20 74 6f 20 74 68 65 20 |argument| to the |
|00005540| 69 6e 74 65 72 70 72 65 | 74 65 72 2e 20 20 49 74 |interpre|ter. It|
|00005550| 20 69 73 20 65 78 65 63 | 75 74 65 64 20 61 73 20 | is exec|uted as |
|00005560| 69 66 0a 61 6e 20 61 6e | 6f 6e 79 6d 6f 75 73 20 |if.an an|onymous |
|00005570| 6d 6f 64 75 6c 65 20 77 | 61 73 20 69 6d 70 6f 72 |module w|as impor|
|00005580| 74 65 64 2e 20 20 53 69 | 6e 63 65 20 7b 5c 74 74 |ted. Si|nce {\tt|
|00005590| 20 69 6d 70 6f 72 74 7d | 20 73 74 61 74 65 6d 65 | import}| stateme|
|000055a0| 6e 74 73 20 61 72 65 0a | 65 78 65 63 75 74 65 64 |nts are.|executed|
|000055b0| 20 6c 69 6b 65 20 61 6c | 6c 20 6f 74 68 65 72 20 | like al|l other |
|000055c0| 73 74 61 74 65 6d 65 6e | 74 73 2c 20 74 68 65 20 |statemen|ts, the |
|000055d0| 69 6e 69 74 69 61 6c 69 | 7a 61 74 69 6f 6e 20 6f |initiali|zation o|
|000055e0| 72 64 65 72 20 6f 66 20 | 74 68 65 0a 6d 6f 64 75 |rder of |the.modu|
|000055f0| 6c 65 73 20 75 73 65 64 | 20 69 6e 20 61 20 70 72 |les used| in a pr|
|00005600| 6f 67 72 61 6d 20 69 73 | 20 64 65 66 69 6e 65 64 |ogram is| defined|
|00005610| 20 62 79 20 74 68 65 20 | 66 6c 6f 77 20 6f 66 20 | by the |flow of |
|00005620| 63 6f 6e 74 72 6f 6c 20 | 74 68 72 6f 75 67 68 0a |control |through.|
|00005630| 74 68 65 20 70 72 6f 67 | 72 61 6d 2e 0a 0a 54 68 |the prog|ram...Th|
|00005640| 65 20 60 61 74 74 72 69 | 62 75 74 65 27 20 6e 6f |e `attri|bute' no|
|00005650| 74 61 74 69 6f 6e 20 7b | 5c 65 6d 20 6d 2e 6e 61 |tation {|\em m.na|
|00005660| 6d 65 7d 2c 20 77 68 65 | 72 65 20 7b 5c 65 6d 20 |me}, whe|re {\em |
|00005670| 6d 7d 20 69 73 20 61 20 | 6d 6f 64 75 6c 65 2c 0a |m} is a |module,.|
|00005680| 61 63 63 65 73 73 65 73 | 20 74 68 65 20 73 79 6d |accesses| the sym|
|00005690| 62 6f 6c 20 7b 5c 65 6d | 20 6e 61 6d 65 7d 20 69 |bol {\em| name} i|
|000056a0| 6e 20 74 68 61 74 20 6d | 6f 64 75 6c 65 27 73 20 |n that m|odule's |
|000056b0| 73 79 6d 62 6f 6c 20 74 | 61 62 6c 65 2e 20 20 49 |symbol t|able. I|
|000056c0| 74 20 63 61 6e 0a 62 65 | 20 61 73 73 69 67 6e 65 |t can.be| assigne|
|000056d0| 64 20 74 6f 20 61 73 20 | 77 65 6c 6c 2e 20 20 54 |d to as |well. T|
|000056e0| 68 69 73 20 69 73 20 69 | 6e 20 66 61 63 74 20 61 |his is i|n fact a|
|000056f0| 20 73 70 65 63 69 61 6c | 20 63 61 73 65 20 6f 66 | special| case of|
|00005700| 20 74 68 65 0a 63 6f 6e | 73 74 72 75 63 74 20 7b | the.con|struct {|
|00005710| 5c 65 6d 20 78 2e 6e 61 | 6d 65 7d 20 77 68 65 72 |\em x.na|me} wher|
|00005720| 65 20 7b 5c 65 6d 20 78 | 7d 20 64 65 6e 6f 74 65 |e {\em x|} denote|
|00005730| 73 20 61 6e 20 61 72 62 | 69 74 72 61 72 79 20 6f |s an arb|itrary o|
|00005740| 62 6a 65 63 74 3b 20 74 | 68 65 0a 74 79 70 65 20 |bject; t|he.type |
|00005750| 6f 66 20 7b 5c 65 6d 20 | 78 7d 20 64 65 74 65 72 |of {\em |x} deter|
|00005760| 6d 69 6e 65 73 20 68 6f | 77 20 74 68 69 73 20 69 |mines ho|w this i|
|00005770| 73 20 74 6f 20 62 65 20 | 69 6e 74 65 72 70 72 65 |s to be |interpre|
|00005780| 74 65 64 2c 20 61 6e 64 | 20 77 68 61 74 0a 61 73 |ted, and| what.as|
|00005790| 73 69 67 6e 6d 65 6e 74 | 20 74 6f 20 69 74 20 6d |signment| to it m|
|000057a0| 65 61 6e 73 2e 0a 0a 46 | 6f 72 20 69 6e 73 74 61 |eans...F|or insta|
|000057b0| 6e 63 65 2c 20 77 68 65 | 6e 20 7b 5c 74 74 20 61 |nce, whe|n {\tt a|
|000057c0| 7d 20 69 73 20 61 20 6c | 69 73 74 20 6f 62 6a 65 |} is a l|ist obje|
|000057d0| 63 74 2c 20 7b 5c 74 74 | 20 61 2e 61 70 70 65 6e |ct, {\tt| a.appen|
|000057e0| 64 7d 20 79 69 65 6c 64 | 73 20 61 0a 62 75 69 6c |d} yield|s a.buil|
|000057f0| 74 2d 69 6e 20 60 6d 65 | 74 68 6f 64 27 20 6f 62 |t-in `me|thod' ob|
|00005800| 6a 65 63 74 20 77 68 69 | 63 68 2c 20 77 68 65 6e |ject whi|ch, when|
|00005810| 20 63 61 6c 6c 65 64 2c | 20 61 70 70 65 6e 64 73 | called,| appends|
|00005820| 20 61 6e 20 69 74 65 6d | 20 74 6f 20 7b 5c 74 74 | an item| to {\tt|
|00005830| 20 61 7d 2e 0a 28 49 66 | 20 7b 5c 74 74 20 61 7d | a}..(If| {\tt a}|
|00005840| 20 61 6e 64 20 7b 5c 74 | 74 20 62 7d 20 61 72 65 | and {\t|t b} are|
|00005850| 20 64 69 73 74 69 6e 63 | 74 20 6c 69 73 74 20 6f | distinc|t list o|
|00005860| 62 6a 65 63 74 73 2c 20 | 7b 5c 74 74 20 61 2e 61 |bjects, |{\tt a.a|
|00005870| 70 70 65 6e 64 7d 20 61 | 6e 64 0a 7b 5c 74 74 20 |ppend} a|nd.{\tt |
|00005880| 62 2e 61 70 70 65 6e 64 | 7d 20 61 72 65 20 64 69 |b.append|} are di|
|00005890| 73 74 69 6e 67 75 69 73 | 68 61 62 6c 65 20 6d 65 |stinguis|hable me|
|000058a0| 74 68 6f 64 20 6f 62 6a | 65 63 74 73 2e 29 20 20 |thod obj|ects.) |
|000058b0| 4e 6f 72 6d 61 6c 6c 79 | 2c 20 69 6e 0a 73 74 61 |Normally|, in.sta|
|000058c0| 74 65 6d 65 6e 74 73 20 | 6c 69 6b 65 20 7b 5c 74 |tements |like {\t|
|000058d0| 74 20 61 2e 61 70 70 65 | 6e 64 28 78 29 7d 2c 20 |t a.appe|nd(x)}, |
|000058e0| 74 68 65 20 6d 65 74 68 | 6f 64 20 6f 62 6a 65 63 |the meth|od objec|
|000058f0| 74 20 7b 5c 74 74 20 61 | 2e 61 70 70 65 6e 64 7d |t {\tt a|.append}|
|00005900| 20 69 73 0a 63 61 6c 6c | 65 64 20 61 6e 64 20 74 | is.call|ed and t|
|00005910| 68 65 6e 20 64 69 73 63 | 61 72 64 65 64 2c 20 62 |hen disc|arded, b|
|00005920| 75 74 20 74 68 69 73 20 | 69 73 20 61 20 6d 61 74 |ut this |is a mat|
|00005930| 74 65 72 20 6f 66 20 63 | 6f 6e 76 65 6e 74 69 6f |ter of c|onventio|
|00005940| 6e 2e 0a 0a 4c 69 73 74 | 20 61 74 74 72 69 62 75 |n...List| attribu|
|00005950| 74 65 73 20 61 72 65 20 | 72 65 61 64 2d 6f 6e 6c |tes are |read-onl|
|00005960| 79 20 2d 2d 2d 20 74 68 | 65 20 75 73 65 72 20 63 |y --- th|e user c|
|00005970| 61 6e 6e 6f 74 20 64 65 | 66 69 6e 65 20 6e 65 77 |annot de|fine new|
|00005980| 20 6c 69 73 74 0a 6d 65 | 74 68 6f 64 73 2e 20 20 | list.me|thods. |
|00005990| 53 6f 6d 65 20 6f 62 6a | 65 63 74 73 2c 20 6c 69 |Some obj|ects, li|
|000059a0| 6b 65 20 6e 75 6d 62 65 | 72 73 20 61 6e 64 20 73 |ke numbe|rs and s|
|000059b0| 74 72 69 6e 67 73 2c 20 | 68 61 76 65 20 6e 6f 20 |trings, |have no |
|000059c0| 61 74 74 72 69 62 75 74 | 65 73 0a 61 74 20 61 6c |attribut|es.at al|
|000059d0| 6c 2e 20 20 4c 69 6b 65 | 20 61 6c 6c 20 74 79 70 |l. Like| all typ|
|000059e0| 65 20 63 68 65 63 6b 69 | 6e 67 20 69 6e 20 50 79 |e checki|ng in Py|
|000059f0| 74 68 6f 6e 2c 20 74 68 | 65 20 6d 65 61 6e 69 6e |thon, th|e meanin|
|00005a00| 67 20 6f 66 20 61 6e 20 | 61 74 74 72 69 62 75 74 |g of an |attribut|
|00005a10| 65 0a 69 73 20 64 65 74 | 65 72 6d 69 6e 65 64 20 |e.is det|ermined |
|00005a20| 61 74 20 72 75 6e 2d 74 | 69 6d 65 20 2d 2d 2d 20 |at run-t|ime --- |
|00005a30| 77 68 65 6e 20 74 68 65 | 20 70 61 72 73 65 72 20 |when the| parser |
|00005a40| 73 65 65 73 20 7b 5c 65 | 6d 20 78 2e 6e 61 6d 65 |sees {\e|m x.name|
|00005a50| 7d 2c 20 69 74 0a 68 61 | 73 20 6e 6f 20 69 64 65 |}, it.ha|s no ide|
|00005a60| 61 20 6f 66 20 74 68 65 | 20 74 79 70 65 20 6f 66 |a of the| type of|
|00005a70| 20 7b 5c 65 6d 20 78 7d | 2e 20 20 4e 6f 74 65 20 | {\em x}|. Note |
|00005a80| 74 68 61 74 20 7b 5c 65 | 6d 20 78 7d 20 68 65 72 |that {\e|m x} her|
|00005a90| 65 20 64 6f 65 73 20 6e | 6f 74 0a 68 61 76 65 20 |e does n|ot.have |
|00005aa0| 74 6f 20 62 65 20 61 20 | 76 61 72 69 61 62 6c 65 |to be a |variable|
|00005ab0| 20 2d 2d 2d 20 69 74 20 | 63 61 6e 20 62 65 20 61 | --- it |can be a|
|00005ac0| 6e 20 61 72 62 69 74 72 | 61 72 79 20 28 70 65 72 |n arbitr|ary (per|
|00005ad0| 68 61 70 73 0a 70 61 72 | 65 6e 74 68 65 73 69 7a |haps.par|enthesiz|
|00005ae0| 65 64 29 20 65 78 70 72 | 65 73 73 69 6f 6e 2e 0a |ed) expr|ession..|
|00005af0| 0a 47 69 76 65 6e 20 74 | 68 65 20 66 6c 65 78 69 |.Given t|he flexi|
|00005b00| 62 69 6c 69 74 79 20 6f | 66 20 74 68 65 20 61 74 |bility o|f the at|
|00005b10| 74 72 69 62 75 74 65 20 | 6e 6f 74 61 74 69 6f 6e |tribute |notation|
|00005b20| 2c 20 6f 6e 65 20 69 73 | 20 74 65 6d 70 74 65 64 |, one is| tempted|
|00005b30| 20 74 6f 20 75 73 65 0a | 6d 65 74 68 6f 64 73 20 | to use.|methods |
|00005b40| 74 6f 20 72 65 70 6c 61 | 63 65 20 61 6c 6c 20 73 |to repla|ce all s|
|00005b50| 74 61 6e 64 61 72 64 20 | 6f 70 65 72 61 74 69 6f |tandard |operatio|
|00005b60| 6e 73 2e 20 20 59 65 74 | 2c 20 50 79 74 68 6f 6e |ns. Yet|, Python|
|00005b70| 20 68 61 73 20 6b 65 70 | 74 20 61 0a 73 6d 61 6c | has kep|t a.smal|
|00005b80| 6c 20 72 65 70 65 72 74 | 6f 69 72 65 20 6f 66 20 |l repert|oire of |
|00005b90| 62 75 69 6c 74 2d 69 6e | 20 66 75 6e 63 74 69 6f |built-in| functio|
|00005ba0| 6e 73 20 6c 69 6b 65 20 | 7b 5c 74 74 20 6c 65 6e |ns like |{\tt len|
|00005bb0| 28 29 7d 20 61 6e 64 20 | 7b 5c 74 74 0a 61 62 73 |()} and |{\tt.abs|
|00005bc0| 28 29 7d 2e 20 20 54 68 | 65 20 72 65 61 73 6f 6e |()}. Th|e reason|
|00005bd0| 20 69 73 20 74 68 61 74 | 20 69 6e 20 73 6f 6d 65 | is that| in some|
|00005be0| 20 63 61 73 65 73 20 74 | 68 65 20 66 75 6e 63 74 | cases t|he funct|
|00005bf0| 69 6f 6e 20 6e 6f 74 61 | 74 69 6f 6e 20 69 73 0a |ion nota|tion is.|
|00005c00| 6d 6f 72 65 20 66 61 6d | 69 6c 69 61 72 20 74 68 |more fam|iliar th|
|00005c10| 61 6e 20 74 68 65 20 6d | 65 74 68 6f 64 20 6e 6f |an the m|ethod no|
|00005c20| 74 61 74 69 6f 6e 3b 20 | 6a 75 73 74 20 6c 69 6b |tation; |just lik|
|00005c30| 65 20 70 72 6f 67 72 61 | 6d 73 20 77 6f 75 6c 64 |e progra|ms would|
|00005c40| 0a 62 65 63 6f 6d 65 20 | 6c 65 73 73 20 72 65 61 |.become |less rea|
|00005c50| 64 61 62 6c 65 20 69 66 | 20 61 6c 6c 20 69 6e 66 |dable if| all inf|
|00005c60| 69 78 20 6f 70 65 72 61 | 74 6f 72 73 20 77 65 72 |ix opera|tors wer|
|00005c70| 65 20 72 65 70 6c 61 63 | 65 64 20 62 79 20 66 75 |e replac|ed by fu|
|00005c80| 6e 63 74 69 6f 6e 0a 63 | 61 6c 6c 73 2c 20 74 68 |nction.c|alls, th|
|00005c90| 65 79 20 77 6f 75 6c 64 | 20 62 65 63 6f 6d 65 20 |ey would| become |
|00005ca0| 6c 65 73 73 20 72 65 61 | 64 61 62 6c 65 20 69 66 |less rea|dable if|
|00005cb0| 20 61 6c 6c 20 66 75 6e | 63 74 69 6f 6e 20 63 61 | all fun|ction ca|
|00005cc0| 6c 6c 73 20 68 61 64 20 | 74 6f 20 62 65 0a 72 65 |lls had |to be.re|
|00005cd0| 70 6c 61 63 65 64 20 62 | 79 20 6d 65 74 68 6f 64 |placed b|y method|
|00005ce0| 20 63 61 6c 6c 73 20 28 | 61 6e 64 20 76 69 63 65 | calls (|and vice|
|00005cf0| 20 76 65 72 73 61 21 29 | 2e 0a 0a 54 68 65 20 63 | versa!)|...The c|
|00005d00| 68 6f 69 63 65 20 77 68 | 65 74 68 65 72 20 74 6f |hoice wh|ether to|
|00005d10| 20 6d 61 6b 65 20 73 6f | 6d 65 74 68 69 6e 67 20 | make so|mething |
|00005d20| 61 20 62 75 69 6c 74 2d | 69 6e 20 66 75 6e 63 74 |a built-|in funct|
|00005d30| 69 6f 6e 20 6f 72 20 61 | 20 6d 65 74 68 6f 64 0a |ion or a| method.|
|00005d40| 69 73 20 61 20 6d 61 74 | 74 65 72 20 6f 66 20 74 |is a mat|ter of t|
|00005d50| 61 73 74 65 2e 20 20 46 | 6f 72 20 61 72 69 74 68 |aste. F|or arith|
|00005d60| 6d 65 74 69 63 20 61 6e | 64 20 73 74 72 69 6e 67 |metic an|d string|
|00005d70| 20 6f 70 65 72 61 74 69 | 6f 6e 73 2c 20 66 75 6e | operati|ons, fun|
|00005d80| 63 74 69 6f 6e 0a 6e 6f | 74 61 74 69 6f 6e 20 69 |ction.no|tation i|
|00005d90| 73 20 70 72 65 66 65 72 | 72 65 64 2c 20 73 69 6e |s prefer|red, sin|
|00005da0| 63 65 20 66 72 65 71 75 | 65 6e 74 6c 79 20 74 68 |ce frequ|ently th|
|00005db0| 65 20 61 72 67 75 6d 65 | 6e 74 20 74 6f 20 73 75 |e argume|nt to su|
|00005dc0| 63 68 20 61 6e 0a 6f 70 | 65 72 61 74 69 6f 6e 20 |ch an.op|eration |
|00005dd0| 69 73 20 61 6e 20 65 78 | 70 72 65 73 73 69 6f 6e |is an ex|pression|
|00005de0| 20 75 73 69 6e 67 20 69 | 6e 66 69 78 20 6e 6f 74 | using i|nfix not|
|00005df0| 61 74 69 6f 6e 2c 20 61 | 73 20 69 6e 20 7b 5c 74 |ation, a|s in {\t|
|00005e00| 74 20 61 62 73 28 61 2b | 62 29 7d 3b 0a 74 68 69 |t abs(a+|b)};.thi|
|00005e10| 73 20 64 65 66 69 6e 69 | 74 65 6c 79 20 6c 6f 6f |s defini|tely loo|
|00005e20| 6b 73 20 62 65 74 74 65 | 72 20 74 68 61 6e 20 7b |ks bette|r than {|
|00005e30| 5c 74 74 20 28 61 2b 62 | 29 2e 61 62 73 28 29 7d |\tt (a+b|).abs()}|
|00005e40| 2e 20 20 54 68 65 20 63 | 68 6f 69 63 65 0a 62 65 |. The c|hoice.be|
|00005e50| 74 77 65 65 6e 20 6d 61 | 6b 65 20 73 6f 6d 65 74 |tween ma|ke somet|
|00005e60| 68 69 6e 67 20 61 20 62 | 75 69 6c 74 2d 69 6e 20 |hing a b|uilt-in |
|00005e70| 66 75 6e 63 74 69 6f 6e | 20 6f 72 20 61 20 66 75 |function| or a fu|
|00005e80| 6e 63 74 69 6f 6e 20 64 | 65 66 69 6e 65 64 20 69 |nction d|efined i|
|00005e90| 6e 20 61 0a 62 75 69 6c | 74 2d 69 6e 20 6d 65 74 |n a.buil|t-in met|
|00005ea0| 68 6f 64 20 28 72 65 71 | 75 69 72 69 6e 67 20 7b |hod (req|uiring {|
|00005eb0| 5c 74 74 20 69 6d 70 6f | 72 74 7d 29 20 69 73 20 |\tt impo|rt}) is |
|00005ec0| 73 69 6d 69 6c 61 72 6c | 79 20 67 75 69 64 65 64 |similarl|y guided|
|00005ed0| 20 62 79 0a 69 6e 74 75 | 69 74 69 6f 6e 3b 20 61 | by.intu|ition; a|
|00005ee0| 6c 6c 20 69 6e 20 61 6c | 6c 2c 20 6f 6e 6c 79 20 |ll in al|l, only |
|00005ef0| 66 75 6e 63 74 69 6f 6e | 73 20 6e 65 65 64 65 64 |function|s needed|
|00005f00| 20 62 79 20 60 67 65 6e | 65 72 61 6c 27 20 70 72 | by `gen|eral' pr|
|00005f10| 6f 67 72 61 6d 6d 69 6e | 67 0a 74 65 63 68 6e 69 |ogrammin|g.techni|
|00005f20| 71 75 65 73 20 61 72 65 | 20 62 75 69 6c 74 2d 69 |ques are| built-i|
|00005f30| 6e 20 66 75 6e 63 74 69 | 6f 6e 73 2e 0a 0a 5c 73 |n functi|ons...\s|
|00005f40| 75 62 73 65 63 74 69 6f | 6e 7b 43 6c 61 73 73 65 |ubsectio|n{Classe|
|00005f50| 73 7d 0a 0a 50 79 74 68 | 6f 6e 20 68 61 73 20 61 |s}..Pyth|on has a|
|00005f60| 20 63 6c 61 73 73 20 6d | 65 63 68 61 6e 69 73 6d | class m|echanism|
|00005f70| 20 64 69 73 74 69 6e 63 | 74 20 66 72 6f 6d 20 74 | distinc|t from t|
|00005f80| 68 65 20 6f 62 6a 65 63 | 74 2d 6f 72 69 65 6e 74 |he objec|t-orient|
|00005f90| 61 74 69 6f 6e 0a 61 6c | 72 65 61 64 79 20 65 78 |ation.al|ready ex|
|00005fa0| 70 6c 61 69 6e 65 64 2e | 20 20 41 20 63 6c 61 73 |plained.| A clas|
|00005fb0| 73 20 69 6e 20 50 79 74 | 68 6f 6e 20 69 73 20 6e |s in Pyt|hon is n|
|00005fc0| 6f 74 20 6d 75 63 68 20 | 6d 6f 72 65 20 74 68 61 |ot much |more tha|
|00005fd0| 6e 20 61 0a 63 6f 6c 6c | 65 63 74 69 6f 6e 20 6f |n a.coll|ection o|
|00005fe0| 66 20 6d 65 74 68 6f 64 | 73 20 61 6e 64 20 61 20 |f method|s and a |
|00005ff0| 77 61 79 20 74 6f 20 63 | 72 65 61 74 65 20 63 6c |way to c|reate cl|
|00006000| 61 73 73 20 69 6e 73 74 | 61 6e 63 65 73 2e 20 20 |ass inst|ances. |
|00006010| 43 6c 61 73 73 0a 6d 65 | 74 68 6f 64 73 20 61 72 |Class.me|thods ar|
|00006020| 65 20 6f 72 64 69 6e 61 | 72 79 20 66 75 6e 63 74 |e ordina|ry funct|
|00006030| 69 6f 6e 73 20 77 68 6f | 73 65 20 66 69 72 73 74 |ions who|se first|
|00006040| 20 70 61 72 61 6d 65 74 | 65 72 20 69 73 20 74 68 | paramet|er is th|
|00006050| 65 20 63 6c 61 73 73 0a | 69 6e 73 74 61 6e 63 65 |e class.|instance|
|00006060| 3b 20 74 68 65 79 20 61 | 72 65 20 63 61 6c 6c 65 |; they a|re calle|
|00006070| 64 20 75 73 69 6e 67 20 | 74 68 65 20 6d 65 74 68 |d using |the meth|
|00006080| 6f 64 20 6e 6f 74 61 74 | 69 6f 6e 2e 0a 0a 46 6f |od notat|ion...Fo|
|00006090| 72 20 69 6e 73 74 61 6e | 63 65 2c 20 61 20 63 6c |r instan|ce, a cl|
|000060a0| 61 73 73 20 63 61 6e 20 | 62 65 20 64 65 66 69 6e |ass can |be defin|
|000060b0| 65 64 20 61 73 20 66 6f | 6c 6c 6f 77 73 3a 0a 5c |ed as fo|llows:.\|
|000060c0| 62 65 67 69 6e 7b 76 65 | 72 62 61 74 69 6d 7d 0a |begin{ve|rbatim}.|
|000060d0| 63 6c 61 73 73 20 46 6f | 6f 3a 0a 20 20 20 64 65 |class Fo|o:. de|
|000060e0| 66 20 6d 65 74 68 31 28 | 73 65 6c 66 2c 20 61 72 |f meth1(|self, ar|
|000060f0| 67 29 3a 20 2e 2e 2e 0a | 20 20 20 64 65 66 20 6d |g): ....| def m|
|00006100| 65 74 68 32 28 73 65 6c | 66 29 3a 20 2e 2e 2e 0a |eth2(sel|f): ....|
|00006110| 5c 65 6e 64 7b 76 65 72 | 62 61 74 69 6d 7d 0a 41 |\end{ver|batim}.A|
|00006120| 20 63 6c 61 73 73 20 69 | 6e 73 74 61 6e 63 65 20 | class i|nstance |
|00006130| 69 73 20 63 72 65 61 74 | 65 64 20 62 79 0a 7b 5c |is creat|ed by.{\|
|00006140| 74 74 20 78 20 3d 20 46 | 6f 6f 28 29 7d 0a 61 6e |tt x = F|oo()}.an|
|00006150| 64 20 69 74 73 20 6d 65 | 74 68 6f 64 73 20 63 61 |d its me|thods ca|
|00006160| 6e 20 62 65 20 63 61 6c | 6c 65 64 20 74 68 75 73 |n be cal|led thus|
|00006170| 3a 0a 5c 62 65 67 69 6e | 7b 76 65 72 62 61 74 69 |:.\begin|{verbati|
|00006180| 6d 7d 0a 78 2e 6d 65 74 | 68 31 28 27 48 69 20 54 |m}.x.met|h1('Hi T|
|00006190| 68 65 72 65 21 27 29 0a | 78 2e 6d 65 74 68 32 28 |here!').|x.meth2(|
|000061a0| 29 0a 5c 65 6e 64 7b 76 | 65 72 62 61 74 69 6d 7d |).\end{v|erbatim}|
|000061b0| 0a 54 68 65 20 66 75 6e | 63 74 69 6f 6e 73 20 75 |.The fun|ctions u|
|000061c0| 73 65 64 20 61 73 20 6d | 65 74 68 6f 64 73 20 61 |sed as m|ethods a|
|000061d0| 72 65 20 61 6c 73 6f 20 | 61 76 61 69 6c 61 62 6c |re also |availabl|
|000061e0| 65 20 61 73 20 61 74 74 | 72 69 62 75 74 65 73 20 |e as att|ributes |
|000061f0| 6f 66 20 74 68 65 0a 63 | 6c 61 73 73 20 6f 62 6a |of the.c|lass obj|
|00006200| 65 63 74 2c 20 61 6e 64 | 20 74 68 65 20 61 62 6f |ect, and| the abo|
|00006210| 76 65 20 6d 65 74 68 6f | 64 20 63 61 6c 6c 73 20 |ve metho|d calls |
|00006220| 63 6f 75 6c 64 20 61 6c | 73 6f 20 68 61 76 65 20 |could al|so have |
|00006230| 62 65 65 6e 20 77 72 69 | 74 74 65 6e 0a 61 73 20 |been wri|tten.as |
|00006240| 66 6f 6c 6c 6f 77 73 3a | 0a 5c 62 65 67 69 6e 7b |follows:|.\begin{|
|00006250| 76 65 72 62 61 74 69 6d | 7d 0a 46 6f 6f 2e 6d 65 |verbatim|}.Foo.me|
|00006260| 74 68 31 28 78 2c 20 27 | 48 69 20 54 68 65 72 65 |th1(x, '|Hi There|
|00006270| 21 27 29 0a 46 6f 6f 2e | 6d 65 74 68 32 28 78 29 |!').Foo.|meth2(x)|
|00006280| 0a 5c 65 6e 64 7b 76 65 | 72 62 61 74 69 6d 7d 0a |.\end{ve|rbatim}.|
|00006290| 43 6c 61 73 73 20 6d 65 | 74 68 6f 64 73 20 63 61 |Class me|thods ca|
|000062a0| 6e 20 73 74 6f 72 65 20 | 69 6e 73 74 61 6e 63 65 |n store |instance|
|000062b0| 20 64 61 74 61 20 62 79 | 20 61 73 73 69 67 6e 69 | data by| assigni|
|000062c0| 6e 67 20 74 6f 20 69 6e | 73 74 61 6e 63 65 20 64 |ng to in|stance d|
|000062d0| 61 74 61 0a 61 74 74 72 | 69 62 75 74 65 73 2c 20 |ata.attr|ibutes, |
|000062e0| 65 2e 67 2e 3a 0a 5c 62 | 65 67 69 6e 7b 76 65 72 |e.g.:.\b|egin{ver|
|000062f0| 62 61 74 69 6d 7d 0a 73 | 65 6c 66 2e 73 69 7a 65 |batim}.s|elf.size|
|00006300| 20 3d 20 31 30 30 0a 73 | 65 6c 66 2e 74 69 74 6c | = 100.s|elf.titl|
|00006310| 65 20 3d 20 27 44 65 61 | 72 20 4a 6f 68 6e 27 0a |e = 'Dea|r John'.|
|00006320| 5c 65 6e 64 7b 76 65 72 | 62 61 74 69 6d 7d 0a 44 |\end{ver|batim}.D|
|00006330| 61 74 61 20 61 74 74 72 | 69 62 75 74 65 73 20 64 |ata attr|ibutes d|
|00006340| 6f 20 6e 6f 74 20 68 61 | 76 65 20 74 6f 20 62 65 |o not ha|ve to be|
|00006350| 20 64 65 63 6c 61 72 65 | 64 3b 20 61 73 20 77 69 | declare|d; as wi|
|00006360| 74 68 20 6c 6f 63 61 6c | 20 76 61 72 69 61 62 6c |th local| variabl|
|00006370| 65 73 2c 0a 74 68 65 79 | 20 73 70 72 69 6e 67 20 |es,.they| spring |
|00006380| 69 6e 74 6f 20 65 78 69 | 73 74 65 6e 63 65 20 77 |into exi|stence w|
|00006390| 68 65 6e 20 61 73 73 69 | 67 6e 65 64 20 74 6f 2e |hen assi|gned to.|
|000063a0| 20 20 49 74 20 69 73 20 | 61 20 6d 61 74 74 65 72 | It is |a matter|
|000063b0| 20 6f 66 0a 64 69 73 63 | 72 65 74 69 6f 6e 20 74 | of.disc|retion t|
|000063c0| 6f 20 61 76 6f 69 64 20 | 6e 61 6d 65 20 63 6f 6e |o avoid |name con|
|000063d0| 66 6c 69 63 74 73 20 77 | 69 74 68 20 6d 65 74 68 |flicts w|ith meth|
|000063e0| 6f 64 20 6e 61 6d 65 73 | 2e 20 20 54 68 69 73 20 |od names|. This |
|000063f0| 66 61 63 69 6c 69 74 79 | 0a 69 73 20 61 6c 73 6f |facility|.is also|
+--------+-------------------------+-------------------------+--------+--------+
Only 25.0 KB of data is shown above.