home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 5 / DATAFILE_PDCD5.iso / utilities / p / python / pytexdoc / ext / lib / lib1 / pickle / tex
LaTeX Document  |  1996-11-08  |  9.2 KB

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

ConfidenceProgramDetectionMatch TypeSupport
100% dexvert LaTeX Document (document/latex) magic Supported
1% dexvert Text File (text/txt) fallback Supported
100% file LaTeX document text default
99% file LaTeX document, ASCII text default
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 73 65 63 74 69 6f 6e | 7b 53 74 61 6e 64 61 72 |\section|{Standar|
|00000010| 64 20 4d 6f 64 75 6c 65 | 20 5c 73 65 63 74 63 6f |d Module| \sectco|
|00000020| 64 65 7b 70 69 63 6b 6c | 65 7d 7d 0a 5c 73 74 6d |de{pickl|e}}.\stm|
|00000030| 6f 64 69 6e 64 65 78 7b | 70 69 63 6b 6c 65 7d 0a |odindex{|pickle}.|
|00000040| 5c 69 6e 64 65 78 7b 70 | 65 72 73 69 73 74 65 6e |\index{p|ersisten|
|00000050| 63 79 7d 0a 5c 69 6e 64 | 65 78 69 69 7b 70 65 72 |cy}.\ind|exii{per|
|00000060| 73 69 73 74 65 6e 74 7d | 7b 6f 62 6a 65 63 74 73 |sistent}|{objects|
|00000070| 7d 0a 5c 69 6e 64 65 78 | 69 69 7b 73 65 72 69 61 |}.\index|ii{seria|
|00000080| 6c 69 7a 69 6e 67 7d 7b | 6f 62 6a 65 63 74 73 7d |lizing}{|objects}|
|00000090| 0a 5c 69 6e 64 65 78 69 | 69 7b 6d 61 72 73 68 61 |.\indexi|i{marsha|
|000000a0| 6c 6c 69 6e 67 7d 7b 6f | 62 6a 65 63 74 73 7d 0a |lling}{o|bjects}.|
|000000b0| 5c 69 6e 64 65 78 69 69 | 7b 66 6c 61 74 74 65 6e |\indexii|{flatten|
|000000c0| 69 6e 67 7d 7b 6f 62 6a | 65 63 74 73 7d 0a 5c 69 |ing}{obj|ects}.\i|
|000000d0| 6e 64 65 78 69 69 7b 70 | 69 63 6b 6c 69 6e 67 7d |ndexii{p|ickling}|
|000000e0| 7b 6f 62 6a 65 63 74 73 | 7d 0a 0a 5c 72 65 6e 65 |{objects|}..\rene|
|000000f0| 77 63 6f 6d 6d 61 6e 64 | 7b 5c 69 6e 64 65 78 73 |wcommand|{\indexs|
|00000100| 75 62 69 74 65 6d 7d 7b | 28 69 6e 20 6d 6f 64 75 |ubitem}{|(in modu|
|00000110| 6c 65 20 70 69 63 6b 6c | 65 29 7d 0a 0a 54 68 65 |le pickl|e)}..The|
|00000120| 20 5c 63 6f 64 65 7b 70 | 69 63 6b 6c 65 7d 20 6d | \code{p|ickle} m|
|00000130| 6f 64 75 6c 65 20 69 6d | 70 6c 65 6d 65 6e 74 73 |odule im|plements|
|00000140| 20 61 20 62 61 73 69 63 | 20 62 75 74 20 70 6f 77 | a basic| but pow|
|00000150| 65 72 66 75 6c 20 61 6c | 67 6f 72 69 74 68 6d 20 |erful al|gorithm |
|00000160| 66 6f 72 0a 60 60 70 69 | 63 6b 6c 69 6e 67 27 27 |for.``pi|ckling''|
|00000170| 20 28 61 2e 6b 2e 61 2e | 5c 20 73 65 72 69 61 6c | (a.k.a.|\ serial|
|00000180| 69 7a 69 6e 67 2c 20 6d | 61 72 73 68 61 6c 6c 69 |izing, m|arshalli|
|00000190| 6e 67 20 6f 72 20 66 6c | 61 74 74 65 6e 69 6e 67 |ng or fl|attening|
|000001a0| 29 20 6e 65 61 72 6c 79 | 0a 61 72 62 69 74 72 61 |) nearly|.arbitra|
|000001b0| 72 79 20 50 79 74 68 6f | 6e 20 6f 62 6a 65 63 74 |ry Pytho|n object|
|000001c0| 73 2e 20 20 54 68 69 73 | 20 69 73 20 74 68 65 20 |s. This| is the |
|000001d0| 61 63 74 20 6f 66 20 63 | 6f 6e 76 65 72 74 69 6e |act of c|onvertin|
|000001e0| 67 20 6f 62 6a 65 63 74 | 73 20 74 6f 20 61 0a 73 |g object|s to a.s|
|000001f0| 74 72 65 61 6d 20 6f 66 | 20 62 79 74 65 73 20 28 |tream of| bytes (|
|00000200| 61 6e 64 20 62 61 63 6b | 3a 20 60 60 75 6e 70 69 |and back|: ``unpi|
|00000210| 63 6b 6c 69 6e 67 27 27 | 29 2e 0a 54 68 69 73 20 |ckling''|)..This |
|00000220| 69 73 20 61 20 6d 6f 72 | 65 20 70 72 69 6d 69 74 |is a mor|e primit|
|00000230| 69 76 65 20 6e 6f 74 69 | 6f 6e 20 74 68 61 6e 0a |ive noti|on than.|
|00000240| 70 65 72 73 69 73 74 65 | 6e 63 79 20 2d 2d 2d 20 |persiste|ncy --- |
|00000250| 61 6c 74 68 6f 75 67 68 | 20 5c 63 6f 64 65 7b 70 |although| \code{p|
|00000260| 69 63 6b 6c 65 7d 20 72 | 65 61 64 73 20 61 6e 64 |ickle} r|eads and|
|00000270| 20 77 72 69 74 65 73 20 | 66 69 6c 65 20 6f 62 6a | writes |file obj|
|00000280| 65 63 74 73 2c 0a 69 74 | 20 64 6f 65 73 20 6e 6f |ects,.it| does no|
|00000290| 74 20 68 61 6e 64 6c 65 | 20 74 68 65 20 69 73 73 |t handle| the iss|
|000002a0| 75 65 20 6f 66 20 6e 61 | 6d 69 6e 67 20 70 65 72 |ue of na|ming per|
|000002b0| 73 69 73 74 65 6e 74 20 | 6f 62 6a 65 63 74 73 2c |sistent |objects,|
|000002c0| 20 6e 6f 72 20 74 68 65 | 0a 28 65 76 65 6e 20 6d | nor the|.(even m|
|000002d0| 6f 72 65 20 63 6f 6d 70 | 6c 69 63 61 74 65 64 29 |ore comp|licated)|
|000002e0| 20 61 72 65 61 20 6f 66 | 20 63 6f 6e 63 75 72 72 | area of| concurr|
|000002f0| 65 6e 74 20 61 63 63 65 | 73 73 20 74 6f 20 70 65 |ent acce|ss to pe|
|00000300| 72 73 69 73 74 65 6e 74 | 0a 6f 62 6a 65 63 74 73 |rsistent|.objects|
|00000310| 2e 20 20 54 68 65 20 5c | 63 6f 64 65 7b 70 69 63 |. The \|code{pic|
|00000320| 6b 6c 65 7d 20 6d 6f 64 | 75 6c 65 20 63 61 6e 20 |kle} mod|ule can |
|00000330| 74 72 61 6e 73 66 6f 72 | 6d 20 61 20 63 6f 6d 70 |transfor|m a comp|
|00000340| 6c 65 78 20 6f 62 6a 65 | 63 74 20 69 6e 74 6f 0a |lex obje|ct into.|
|00000350| 61 20 62 79 74 65 20 73 | 74 72 65 61 6d 20 61 6e |a byte s|tream an|
|00000360| 64 20 69 74 20 63 61 6e | 20 74 72 61 6e 73 66 6f |d it can| transfo|
|00000370| 72 6d 20 74 68 65 20 62 | 79 74 65 20 73 74 72 65 |rm the b|yte stre|
|00000380| 61 6d 20 69 6e 74 6f 20 | 61 6e 20 6f 62 6a 65 63 |am into |an objec|
|00000390| 74 20 77 69 74 68 0a 74 | 68 65 20 73 61 6d 65 20 |t with.t|he same |
|000003a0| 69 6e 74 65 72 6e 61 6c | 20 73 74 72 75 63 74 75 |internal| structu|
|000003b0| 72 65 2e 20 20 54 68 65 | 20 6d 6f 73 74 20 6f 62 |re. The| most ob|
|000003c0| 76 69 6f 75 73 20 74 68 | 69 6e 67 20 74 6f 20 64 |vious th|ing to d|
|000003d0| 6f 20 77 69 74 68 20 74 | 68 65 73 65 0a 62 79 74 |o with t|hese.byt|
|000003e0| 65 20 73 74 72 65 61 6d | 73 20 69 73 20 74 6f 20 |e stream|s is to |
|000003f0| 77 72 69 74 65 20 74 68 | 65 6d 20 6f 6e 74 6f 20 |write th|em onto |
|00000400| 61 20 66 69 6c 65 2c 20 | 62 75 74 20 69 74 20 69 |a file, |but it i|
|00000410| 73 20 61 6c 73 6f 20 63 | 6f 6e 63 65 69 76 61 62 |s also c|onceivab|
|00000420| 6c 65 0a 74 6f 20 73 65 | 6e 64 20 74 68 65 6d 20 |le.to se|nd them |
|00000430| 61 63 72 6f 73 73 20 61 | 20 6e 65 74 77 6f 72 6b |across a| network|
|00000440| 20 6f 72 20 73 74 6f 72 | 65 20 74 68 65 6d 20 69 | or stor|e them i|
|00000450| 6e 20 61 20 64 61 74 61 | 62 61 73 65 2e 20 20 54 |n a data|base. T|
|00000460| 68 65 20 6d 6f 64 75 6c | 65 0a 5c 63 6f 64 65 7b |he modul|e.\code{|
|00000470| 73 68 65 6c 76 65 7d 20 | 70 72 6f 76 69 64 65 73 |shelve} |provides|
|00000480| 20 61 20 73 69 6d 70 6c | 65 20 69 6e 74 65 72 66 | a simpl|e interf|
|00000490| 61 63 65 20 74 6f 20 70 | 69 63 6b 6c 65 20 61 6e |ace to p|ickle an|
|000004a0| 64 20 75 6e 70 69 63 6b | 6c 65 0a 6f 62 6a 65 63 |d unpick|le.objec|
|000004b0| 74 73 20 6f 6e 20 60 60 | 64 62 6d 27 27 2d 73 74 |ts on ``|dbm''-st|
|000004c0| 79 6c 65 20 64 61 74 61 | 62 61 73 65 20 66 69 6c |yle data|base fil|
|000004d0| 65 73 2e 0a 5c 73 74 6d | 6f 64 69 6e 64 65 78 7b |es..\stm|odindex{|
|000004e0| 73 68 65 6c 76 65 7d 0a | 0a 55 6e 6c 69 6b 65 20 |shelve}.|.Unlike |
|000004f0| 74 68 65 20 62 75 69 6c | 74 2d 69 6e 20 6d 6f 64 |the buil|t-in mod|
|00000500| 75 6c 65 20 5c 63 6f 64 | 65 7b 6d 61 72 73 68 61 |ule \cod|e{marsha|
|00000510| 6c 7d 2c 20 5c 63 6f 64 | 65 7b 70 69 63 6b 6c 65 |l}, \cod|e{pickle|
|00000520| 7d 20 68 61 6e 64 6c 65 | 73 20 74 68 65 0a 66 6f |} handle|s the.fo|
|00000530| 6c 6c 6f 77 69 6e 67 20 | 63 6f 72 72 65 63 74 6c |llowing |correctl|
|00000540| 79 3a 0a 5c 73 74 6d 6f | 64 69 6e 64 65 78 7b 6d |y:.\stmo|dindex{m|
|00000550| 61 72 73 68 61 6c 7d 0a | 0a 5c 62 65 67 69 6e 7b |arshal}.|.\begin{|
|00000560| 69 74 65 6d 69 7a 65 7d | 0a 0a 5c 69 74 65 6d 20 |itemize}|..\item |
|00000570| 72 65 63 75 72 73 69 76 | 65 20 6f 62 6a 65 63 74 |recursiv|e object|
|00000580| 73 20 28 6f 62 6a 65 63 | 74 73 20 63 6f 6e 74 61 |s (objec|ts conta|
|00000590| 69 6e 69 6e 67 20 72 65 | 66 65 72 65 6e 63 65 73 |ining re|ferences|
|000005a0| 20 74 6f 20 74 68 65 6d | 73 65 6c 76 65 73 29 0a | to them|selves).|
|000005b0| 0a 5c 69 74 65 6d 20 6f | 62 6a 65 63 74 20 73 68 |.\item o|bject sh|
|000005c0| 61 72 69 6e 67 20 28 72 | 65 66 65 72 65 6e 63 65 |aring (r|eference|
|000005d0| 73 20 74 6f 20 74 68 65 | 20 73 61 6d 65 20 6f 62 |s to the| same ob|
|000005e0| 6a 65 63 74 20 69 6e 20 | 64 69 66 66 65 72 65 6e |ject in |differen|
|000005f0| 74 20 70 6c 61 63 65 73 | 29 0a 0a 5c 69 74 65 6d |t places|)..\item|
|00000600| 20 75 73 65 72 2d 64 65 | 66 69 6e 65 64 20 63 6c | user-de|fined cl|
|00000610| 61 73 73 65 73 20 61 6e | 64 20 74 68 65 69 72 20 |asses an|d their |
|00000620| 69 6e 73 74 61 6e 63 65 | 73 0a 0a 5c 65 6e 64 7b |instance|s..\end{|
|00000630| 69 74 65 6d 69 7a 65 7d | 0a 0a 54 68 65 20 64 61 |itemize}|..The da|
|00000640| 74 61 20 66 6f 72 6d 61 | 74 20 75 73 65 64 20 62 |ta forma|t used b|
|00000650| 79 20 5c 63 6f 64 65 7b | 70 69 63 6b 6c 65 7d 20 |y \code{|pickle} |
|00000660| 69 73 20 50 79 74 68 6f | 6e 2d 73 70 65 63 69 66 |is Pytho|n-specif|
|00000670| 69 63 2e 20 20 54 68 69 | 73 20 68 61 73 0a 74 68 |ic. Thi|s has.th|
|00000680| 65 20 61 64 76 61 6e 74 | 61 67 65 20 74 68 61 74 |e advant|age that|
|00000690| 20 74 68 65 72 65 20 61 | 72 65 20 6e 6f 20 72 65 | there a|re no re|
|000006a0| 73 74 72 69 63 74 69 6f | 6e 73 20 69 6d 70 6f 73 |strictio|ns impos|
|000006b0| 65 64 20 62 79 20 65 78 | 74 65 72 6e 61 6c 0a 73 |ed by ex|ternal.s|
|000006c0| 74 61 6e 64 61 72 64 73 | 20 73 75 63 68 20 61 73 |tandards| such as|
|000006d0| 20 43 4f 52 42 41 20 28 | 77 68 69 63 68 20 70 72 | CORBA (|which pr|
|000006e0| 6f 62 61 62 6c 79 20 63 | 61 6e 27 74 20 72 65 70 |obably c|an't rep|
|000006f0| 72 65 73 65 6e 74 20 70 | 6f 69 6e 74 65 72 0a 73 |resent p|ointer.s|
|00000700| 68 61 72 69 6e 67 20 6f | 72 20 72 65 63 75 72 73 |haring o|r recurs|
|00000710| 69 76 65 20 6f 62 6a 65 | 63 74 73 29 3b 20 68 6f |ive obje|cts); ho|
|00000720| 77 65 76 65 72 20 69 74 | 20 6d 65 61 6e 73 20 74 |wever it| means t|
|00000730| 68 61 74 20 6e 6f 6e 2d | 50 79 74 68 6f 6e 0a 70 |hat non-|Python.p|
|00000740| 72 6f 67 72 61 6d 73 20 | 6d 61 79 20 6e 6f 74 20 |rograms |may not |
|00000750| 62 65 20 61 62 6c 65 20 | 74 6f 20 72 65 63 6f 6e |be able |to recon|
|00000760| 73 74 72 75 63 74 20 70 | 69 63 6b 6c 65 64 20 50 |struct p|ickled P|
|00000770| 79 74 68 6f 6e 20 6f 62 | 6a 65 63 74 73 2e 0a 0a |ython ob|jects...|
|00000780| 54 68 65 20 5c 63 6f 64 | 65 7b 70 69 63 6b 6c 65 |The \cod|e{pickle|
|00000790| 7d 20 64 61 74 61 20 66 | 6f 72 6d 61 74 20 75 73 |} data f|ormat us|
|000007a0| 65 73 20 61 20 70 72 69 | 6e 74 61 62 6c 65 20 5c |es a pri|ntable \|
|000007b0| 41 53 43 49 49 7b 7d 20 | 72 65 70 72 65 73 65 6e |ASCII{} |represen|
|000007c0| 74 61 74 69 6f 6e 2e 0a | 54 68 69 73 20 69 73 20 |tation..|This is |
|000007d0| 73 6c 69 67 68 74 6c 79 | 20 6d 6f 72 65 20 76 6f |slightly| more vo|
|000007e0| 6c 75 6d 69 6e 6f 75 73 | 20 74 68 61 6e 20 61 20 |luminous| than a |
|000007f0| 62 69 6e 61 72 79 20 72 | 65 70 72 65 73 65 6e 74 |binary r|epresent|
|00000800| 61 74 69 6f 6e 2e 0a 48 | 6f 77 65 76 65 72 2c 20 |ation..H|owever, |
|00000810| 73 6d 61 6c 6c 20 69 6e | 74 65 67 65 72 73 20 61 |small in|tegers a|
|00000820| 63 74 75 61 6c 6c 79 20 | 74 61 6b 65 20 7b 5c 65 |ctually |take {\e|
|00000830| 6d 20 6c 65 73 73 7d 20 | 73 70 61 63 65 20 77 68 |m less} |space wh|
|00000840| 65 6e 0a 72 65 70 72 65 | 73 65 6e 74 65 64 20 61 |en.repre|sented a|
|00000850| 73 20 6d 69 6e 69 6d 61 | 6c 2d 73 69 7a 65 20 64 |s minima|l-size d|
|00000860| 65 63 69 6d 61 6c 20 73 | 74 72 69 6e 67 73 20 74 |ecimal s|trings t|
|00000870| 68 61 6e 20 77 68 65 6e | 20 72 65 70 72 65 73 65 |han when| represe|
|00000880| 6e 74 65 64 20 61 73 0a | 33 32 2d 62 69 74 20 62 |nted as.|32-bit b|
|00000890| 69 6e 61 72 79 20 6e 75 | 6d 62 65 72 73 2c 20 61 |inary nu|mbers, a|
|000008a0| 6e 64 20 73 74 72 69 6e | 67 73 20 61 72 65 20 6f |nd strin|gs are o|
|000008b0| 6e 6c 79 20 6d 75 63 68 | 20 6c 6f 6e 67 65 72 20 |nly much| longer |
|000008c0| 69 66 20 74 68 65 79 0a | 63 6f 6e 74 61 69 6e 20 |if they.|contain |
|000008d0| 6d 61 6e 79 20 63 6f 6e | 74 72 6f 6c 20 63 68 61 |many con|trol cha|
|000008e0| 72 61 63 74 65 72 73 20 | 6f 72 20 38 2d 62 69 74 |racters |or 8-bit|
|000008f0| 20 63 68 61 72 61 63 74 | 65 72 73 2e 20 20 54 68 | charact|ers. Th|
|00000900| 65 20 62 69 67 0a 61 64 | 76 61 6e 74 61 67 65 20 |e big.ad|vantage |
|00000910| 6f 66 20 75 73 69 6e 67 | 20 70 72 69 6e 74 61 62 |of using| printab|
|00000920| 6c 65 20 5c 41 53 43 49 | 49 7b 7d 20 28 61 6e 64 |le \ASCI|I{} (and|
|00000930| 20 6f 66 20 73 6f 6d 65 | 20 6f 74 68 65 72 20 63 | of some| other c|
|00000940| 68 61 72 61 63 74 65 72 | 69 73 74 69 63 73 0a 6f |haracter|istics.o|
|00000950| 66 20 5c 63 6f 64 65 7b | 70 69 63 6b 6c 65 7d 27 |f \code{|pickle}'|
|00000960| 73 20 72 65 70 72 65 73 | 65 6e 74 61 74 69 6f 6e |s repres|entation|
|00000970| 29 20 69 73 20 74 68 61 | 74 20 66 6f 72 20 64 65 |) is tha|t for de|
|00000980| 62 75 67 67 69 6e 67 20 | 6f 72 20 72 65 63 6f 76 |bugging |or recov|
|00000990| 65 72 79 0a 70 75 72 70 | 6f 73 65 73 20 69 74 20 |ery.purp|oses it |
|000009a0| 69 73 20 70 6f 73 73 69 | 62 6c 65 20 66 6f 72 20 |is possi|ble for |
|000009b0| 61 20 68 75 6d 61 6e 20 | 74 6f 20 72 65 61 64 20 |a human |to read |
|000009c0| 74 68 65 20 70 69 63 6b | 6c 65 64 20 66 69 6c 65 |the pick|led file|
|000009d0| 20 77 69 74 68 20 61 0a | 73 74 61 6e 64 61 72 64 | with a.|standard|
|000009e0| 20 74 65 78 74 20 65 64 | 69 74 6f 72 2e 20 20 28 | text ed|itor. (|
|000009f0| 49 20 63 6f 75 6c 64 20 | 68 61 76 65 20 67 6f 6e |I could |have gon|
|00000a00| 65 20 61 20 73 74 65 70 | 20 66 75 72 74 68 65 72 |e a step| further|
|00000a10| 20 61 6e 64 20 75 73 65 | 64 20 61 0a 6e 6f 74 61 | and use|d a.nota|
|00000a20| 74 69 6f 6e 20 6c 69 6b | 65 20 53 2d 65 78 70 72 |tion lik|e S-expr|
|00000a30| 65 73 73 69 6f 6e 73 2c | 20 62 75 74 20 74 68 65 |essions,| but the|
|00000a40| 20 70 61 72 73 65 72 0a | 28 63 75 72 72 65 6e 74 | parser.|(current|
|00000a50| 6c 79 20 77 72 69 74 74 | 65 6e 20 69 6e 20 50 79 |ly writt|en in Py|
|00000a60| 74 68 6f 6e 29 20 77 6f | 75 6c 64 20 68 61 76 65 |thon) wo|uld have|
|00000a70| 20 62 65 65 6e 0a 63 6f | 6e 73 69 64 65 72 61 62 | been.co|nsiderab|
|00000a80| 6c 79 20 6d 6f 72 65 20 | 63 6f 6d 70 6c 69 63 61 |ly more |complica|
|00000a90| 74 65 64 20 61 6e 64 20 | 73 6c 6f 77 65 72 2c 20 |ted and |slower, |
|00000aa0| 61 6e 64 20 74 68 65 20 | 66 69 6c 65 73 20 77 6f |and the |files wo|
|00000ab0| 75 6c 64 20 70 72 6f 62 | 61 62 6c 79 0a 68 61 76 |uld prob|ably.hav|
|00000ac0| 65 20 62 65 63 6f 6d 65 | 20 6d 75 63 68 20 6c 61 |e become| much la|
|00000ad0| 72 67 65 72 2e 29 0a 0a | 54 68 65 20 5c 63 6f 64 |rger.)..|The \cod|
|00000ae0| 65 7b 70 69 63 6b 6c 65 | 7d 20 6d 6f 64 75 6c 65 |e{pickle|} module|
|00000af0| 20 64 6f 65 73 6e 27 74 | 20 68 61 6e 64 6c 65 20 | doesn't| handle |
|00000b00| 63 6f 64 65 20 6f 62 6a | 65 63 74 73 2c 20 77 68 |code obj|ects, wh|
|00000b10| 69 63 68 20 74 68 65 0a | 5c 63 6f 64 65 7b 6d 61 |ich the.|\code{ma|
|00000b20| 72 73 68 61 6c 7d 20 6d | 6f 64 75 6c 65 20 64 6f |rshal} m|odule do|
|00000b30| 65 73 2e 20 20 49 20 73 | 75 70 70 6f 73 65 20 5c |es. I s|uppose \|
|00000b40| 63 6f 64 65 7b 70 69 63 | 6b 6c 65 7d 20 63 6f 75 |code{pic|kle} cou|
|00000b50| 6c 64 2c 20 61 6e 64 20 | 6d 61 79 62 65 0a 69 74 |ld, and |maybe.it|
|00000b60| 20 73 68 6f 75 6c 64 2c | 20 62 75 74 20 74 68 65 | should,| but the|
|00000b70| 72 65 27 73 20 70 72 6f | 62 61 62 6c 79 20 6e 6f |re's pro|bably no|
|00000b80| 20 67 72 65 61 74 20 6e | 65 65 64 20 66 6f 72 20 | great n|eed for |
|00000b90| 69 74 20 72 69 67 68 74 | 20 6e 6f 77 20 28 61 73 |it right| now (as|
|00000ba0| 0a 6c 6f 6e 67 20 61 73 | 20 5c 63 6f 64 65 7b 6d |.long as| \code{m|
|00000bb0| 61 72 73 68 61 6c 7d 20 | 63 6f 6e 74 69 6e 75 65 |arshal} |continue|
|00000bc0| 73 20 74 6f 20 62 65 20 | 75 73 65 64 20 66 6f 72 |s to be |used for|
|00000bd0| 20 72 65 61 64 69 6e 67 | 20 61 6e 64 20 77 72 69 | reading| and wri|
|00000be0| 74 69 6e 67 0a 63 6f 64 | 65 20 6f 62 6a 65 63 74 |ting.cod|e object|
|00000bf0| 73 29 2c 20 61 6e 64 20 | 61 74 20 6c 65 61 73 74 |s), and |at least|
|00000c00| 20 74 68 69 73 20 61 76 | 6f 69 64 73 20 74 68 65 | this av|oids the|
|00000c10| 20 70 6f 73 73 69 62 69 | 6c 69 74 79 20 6f 66 20 | possibi|lity of |
|00000c20| 73 6d 75 67 67 6c 69 6e | 67 0a 54 72 6f 6a 61 6e |smugglin|g.Trojan|
|00000c30| 20 68 6f 72 73 65 73 20 | 69 6e 74 6f 20 61 20 70 | horses |into a p|
|00000c40| 72 6f 67 72 61 6d 2e 0a | 5c 73 74 6d 6f 64 69 6e |rogram..|\stmodin|
|00000c50| 64 65 78 7b 6d 61 72 73 | 68 61 6c 7d 0a 0a 46 6f |dex{mars|hal}..Fo|
|00000c60| 72 20 74 68 65 20 62 65 | 6e 65 66 69 74 20 6f 66 |r the be|nefit of|
|00000c70| 20 70 65 72 73 69 73 74 | 65 6e 63 79 20 6d 6f 64 | persist|ency mod|
|00000c80| 75 6c 65 73 20 77 72 69 | 74 74 65 6e 20 75 73 69 |ules wri|tten usi|
|00000c90| 6e 67 20 5c 63 6f 64 65 | 7b 70 69 63 6b 6c 65 7d |ng \code|{pickle}|
|00000ca0| 2c 20 69 74 0a 73 75 70 | 70 6f 72 74 73 20 74 68 |, it.sup|ports th|
|00000cb0| 65 20 6e 6f 74 69 6f 6e | 20 6f 66 20 61 20 72 65 |e notion| of a re|
|00000cc0| 66 65 72 65 6e 63 65 20 | 74 6f 20 61 6e 20 6f 62 |ference |to an ob|
|00000cd0| 6a 65 63 74 20 6f 75 74 | 73 69 64 65 20 74 68 65 |ject out|side the|
|00000ce0| 20 70 69 63 6b 6c 65 64 | 0a 64 61 74 61 20 73 74 | pickled|.data st|
|00000cf0| 72 65 61 6d 2e 20 20 53 | 75 63 68 20 6f 62 6a 65 |ream. S|uch obje|
|00000d00| 63 74 73 20 61 72 65 20 | 72 65 66 65 72 65 6e 63 |cts are |referenc|
|00000d10| 65 64 20 62 79 20 61 20 | 6e 61 6d 65 2c 20 77 68 |ed by a |name, wh|
|00000d20| 69 63 68 20 69 73 20 61 | 6e 0a 61 72 62 69 74 72 |ich is a|n.arbitr|
|00000d30| 61 72 79 20 73 74 72 69 | 6e 67 20 6f 66 20 70 72 |ary stri|ng of pr|
|00000d40| 69 6e 74 61 62 6c 65 20 | 5c 41 53 43 49 49 7b 7d |intable |\ASCII{}|
|00000d50| 20 63 68 61 72 61 63 74 | 65 72 73 2e 20 20 54 68 | charact|ers. Th|
|00000d60| 65 20 72 65 73 6f 6c 75 | 74 69 6f 6e 20 6f 66 0a |e resolu|tion of.|
|00000d70| 73 75 63 68 20 6e 61 6d | 65 73 20 69 73 20 6e 6f |such nam|es is no|
|00000d80| 74 20 64 65 66 69 6e 65 | 64 20 62 79 20 74 68 65 |t define|d by the|
|00000d90| 20 5c 63 6f 64 65 7b 70 | 69 63 6b 6c 65 7d 20 6d | \code{p|ickle} m|
|00000da0| 6f 64 75 6c 65 20 2d 2d | 2d 20 74 68 65 0a 70 65 |odule --|- the.pe|
|00000db0| 72 73 69 73 74 65 6e 74 | 20 6f 62 6a 65 63 74 20 |rsistent| object |
|00000dc0| 6d 6f 64 75 6c 65 20 77 | 69 6c 6c 20 68 61 76 65 |module w|ill have|
|00000dd0| 20 74 6f 20 69 6d 70 6c | 65 6d 65 6e 74 20 61 20 | to impl|ement a |
|00000de0| 6d 65 74 68 6f 64 0a 5c | 63 6f 64 65 7b 70 65 72 |method.\|code{per|
|00000df0| 73 69 73 74 65 6e 74 5f | 6c 6f 61 64 7d 2e 20 20 |sistent_|load}. |
|00000e00| 54 6f 20 77 72 69 74 65 | 20 72 65 66 65 72 65 6e |To write| referen|
|00000e10| 63 65 73 20 74 6f 20 70 | 65 72 73 69 73 74 65 6e |ces to p|ersisten|
|00000e20| 74 20 6f 62 6a 65 63 74 | 73 2c 0a 74 68 65 20 70 |t object|s,.the p|
|00000e30| 65 72 73 69 73 74 65 6e | 74 20 6d 6f 64 75 6c 65 |ersisten|t module|
|00000e40| 20 6d 75 73 74 20 64 65 | 66 69 6e 65 20 61 20 6d | must de|fine a m|
|00000e50| 65 74 68 6f 64 20 5c 63 | 6f 64 65 7b 70 65 72 73 |ethod \c|ode{pers|
|00000e60| 69 73 74 65 6e 74 5f 69 | 64 7d 20 77 68 69 63 68 |istent_i|d} which|
|00000e70| 0a 72 65 74 75 72 6e 73 | 20 65 69 74 68 65 72 20 |.returns| either |
|00000e80| 5c 63 6f 64 65 7b 4e 6f | 6e 65 7d 20 6f 72 20 74 |\code{No|ne} or t|
|00000e90| 68 65 20 70 65 72 73 69 | 73 74 65 6e 74 20 49 44 |he persi|stent ID|
|00000ea0| 20 6f 66 20 74 68 65 20 | 6f 62 6a 65 63 74 2e 0a | of the |object..|
|00000eb0| 0a 54 68 65 72 65 20 61 | 72 65 20 73 6f 6d 65 20 |.There a|re some |
|00000ec0| 72 65 73 74 72 69 63 74 | 69 6f 6e 73 20 6f 6e 20 |restrict|ions on |
|00000ed0| 74 68 65 20 70 69 63 6b | 6c 69 6e 67 20 6f 66 20 |the pick|ling of |
|00000ee0| 63 6c 61 73 73 20 69 6e | 73 74 61 6e 63 65 73 2e |class in|stances.|
|00000ef0| 0a 0a 46 69 72 73 74 20 | 6f 66 20 61 6c 6c 2c 20 |..First |of all, |
|00000f00| 74 68 65 20 63 6c 61 73 | 73 20 6d 75 73 74 20 62 |the clas|s must b|
|00000f10| 65 20 64 65 66 69 6e 65 | 64 20 61 74 20 74 68 65 |e define|d at the|
|00000f20| 20 74 6f 70 20 6c 65 76 | 65 6c 20 69 6e 20 61 20 | top lev|el in a |
|00000f30| 6d 6f 64 75 6c 65 2e 0a | 0a 5c 72 65 6e 65 77 63 |module..|.\renewc|
|00000f40| 6f 6d 6d 61 6e 64 7b 5c | 69 6e 64 65 78 73 75 62 |ommand{\|indexsub|
|00000f50| 69 74 65 6d 7d 7b 28 70 | 69 63 6b 6c 65 20 70 72 |item}{(p|ickle pr|
|00000f60| 6f 74 6f 63 6f 6c 29 7d | 0a 0a 4e 65 78 74 2c 20 |otocol)}|..Next, |
|00000f70| 69 74 20 6d 75 73 74 20 | 6e 6f 72 6d 61 6c 6c 79 |it must |normally|
|00000f80| 20 62 65 20 70 6f 73 73 | 69 62 6c 65 20 74 6f 20 | be poss|ible to |
|00000f90| 63 72 65 61 74 65 20 63 | 6c 61 73 73 20 69 6e 73 |create c|lass ins|
|00000fa0| 74 61 6e 63 65 73 20 62 | 79 0a 63 61 6c 6c 69 6e |tances b|y.callin|
|00000fb0| 67 20 74 68 65 20 63 6c | 61 73 73 20 77 69 74 68 |g the cl|ass with|
|00000fc0| 6f 75 74 20 61 72 67 75 | 6d 65 6e 74 73 2e 20 20 |out argu|ments. |
|00000fd0| 55 73 75 61 6c 6c 79 2c | 20 74 68 69 73 20 69 73 |Usually,| this is|
|00000fe0| 20 62 65 73 74 0a 61 63 | 63 6f 6d 70 6c 69 73 68 | best.ac|complish|
|00000ff0| 65 64 20 62 79 20 70 72 | 6f 76 69 64 69 6e 67 20 |ed by pr|oviding |
|00001000| 64 65 66 61 75 6c 74 20 | 76 61 6c 75 65 73 20 66 |default |values f|
|00001010| 6f 72 20 61 6c 6c 20 61 | 72 67 75 6d 65 6e 74 73 |or all a|rguments|
|00001020| 20 74 6f 20 69 74 73 0a | 5c 63 6f 64 65 7b 5f 5f | to its.|\code{__|
|00001030| 69 6e 69 74 5f 5f 7d 20 | 6d 65 74 68 6f 64 20 28 |init__} |method (|
|00001040| 69 66 20 69 74 20 68 61 | 73 20 6f 6e 65 29 2e 20 |if it ha|s one). |
|00001050| 20 49 66 20 74 68 69 73 | 20 69 73 20 75 6e 64 65 | If this| is unde|
|00001060| 73 69 72 61 62 6c 65 2c | 20 74 68 65 0a 63 6c 61 |sirable,| the.cla|
|00001070| 73 73 20 63 61 6e 20 64 | 65 66 69 6e 65 20 61 20 |ss can d|efine a |
|00001080| 6d 65 74 68 6f 64 20 5c | 63 6f 64 65 7b 5f 5f 67 |method \|code{__g|
|00001090| 65 74 69 6e 69 74 61 72 | 67 73 5f 5f 28 29 7d 2c |etinitar|gs__()},|
|000010a0| 20 77 68 69 63 68 20 73 | 68 6f 75 6c 64 0a 72 65 | which s|hould.re|
|000010b0| 74 75 72 6e 20 61 20 7b | 5c 65 6d 20 74 75 70 6c |turn a {|\em tupl|
|000010c0| 65 7d 20 63 6f 6e 74 61 | 69 6e 69 6e 67 20 74 68 |e} conta|ining th|
|000010d0| 65 20 61 72 67 75 6d 65 | 6e 74 73 20 74 6f 20 62 |e argume|nts to b|
|000010e0| 65 20 70 61 73 73 65 64 | 20 74 6f 20 74 68 65 0a |e passed| to the.|
|000010f0| 63 6c 61 73 73 20 63 6f | 6e 73 74 72 75 63 74 6f |class co|nstructo|
|00001100| 72 20 28 5c 63 6f 64 65 | 7b 5f 5f 69 6e 69 74 5f |r (\code|{__init_|
|00001110| 5f 28 29 7d 29 2e 0a 5c | 74 74 69 6e 64 65 78 7b |_()})..\|ttindex{|
|00001120| 5f 5f 67 65 74 69 6e 69 | 74 61 72 67 73 5f 5f 7d |__getini|targs__}|
|00001130| 0a 5c 74 74 69 6e 64 65 | 78 7b 5f 5f 69 6e 69 74 |.\ttinde|x{__init|
|00001140| 5f 5f 7d 0a 0a 43 6c 61 | 73 73 65 73 20 63 61 6e |__}..Cla|sses can|
|00001150| 20 66 75 72 74 68 65 72 | 20 69 6e 66 6c 75 65 6e | further| influen|
|00001160| 63 65 20 68 6f 77 20 74 | 68 65 69 72 20 69 6e 73 |ce how t|heir ins|
|00001170| 74 61 6e 63 65 73 20 61 | 72 65 20 70 69 63 6b 6c |tances a|re pickl|
|00001180| 65 64 20 2d 2d 2d 20 69 | 66 20 74 68 65 20 63 6c |ed --- i|f the cl|
|00001190| 61 73 73 0a 64 65 66 69 | 6e 65 73 20 74 68 65 20 |ass.defi|nes the |
|000011a0| 6d 65 74 68 6f 64 20 5c | 63 6f 64 65 7b 5f 5f 67 |method \|code{__g|
|000011b0| 65 74 73 74 61 74 65 5f | 5f 28 29 7d 2c 20 69 74 |etstate_|_()}, it|
|000011c0| 20 69 73 20 63 61 6c 6c | 65 64 20 61 6e 64 20 74 | is call|ed and t|
|000011d0| 68 65 20 72 65 74 75 72 | 6e 0a 73 74 61 74 65 20 |he retur|n.state |
|000011e0| 69 73 20 70 69 63 6b 6c | 65 64 20 61 73 20 74 68 |is pickl|ed as th|
|000011f0| 65 20 63 6f 6e 74 65 6e | 74 73 20 66 6f 72 20 74 |e conten|ts for t|
|00001200| 68 65 20 69 6e 73 74 61 | 6e 63 65 2c 20 61 6e 64 |he insta|nce, and|
|00001210| 20 69 66 20 74 68 65 20 | 63 6c 61 73 73 0a 64 65 | if the |class.de|
|00001220| 66 69 6e 65 73 20 74 68 | 65 20 6d 65 74 68 6f 64 |fines th|e method|
|00001230| 20 5c 63 6f 64 65 7b 5f | 5f 73 65 74 73 74 61 74 | \code{_|_setstat|
|00001240| 65 5f 5f 28 29 7d 2c 20 | 69 74 20 69 73 20 63 61 |e__()}, |it is ca|
|00001250| 6c 6c 65 64 20 77 69 74 | 68 20 74 68 65 0a 75 6e |lled wit|h the.un|
|00001260| 70 69 63 6b 6c 65 64 20 | 73 74 61 74 65 2e 20 20 |pickled |state. |
|00001270| 28 4e 6f 74 65 20 74 68 | 61 74 20 74 68 65 73 65 |(Note th|at these|
|00001280| 20 6d 65 74 68 6f 64 73 | 20 63 61 6e 20 61 6c 73 | methods| can als|
|00001290| 6f 20 62 65 20 75 73 65 | 64 20 74 6f 0a 69 6d 70 |o be use|d to.imp|
|000012a0| 6c 65 6d 65 6e 74 20 63 | 6f 70 79 69 6e 67 20 63 |lement c|opying c|
|000012b0| 6c 61 73 73 20 69 6e 73 | 74 61 6e 63 65 73 2e 29 |lass ins|tances.)|
|000012c0| 20 20 49 66 20 74 68 65 | 72 65 20 69 73 20 6e 6f | If the|re is no|
|000012d0| 0a 5c 63 6f 64 65 7b 5f | 5f 67 65 74 73 74 61 74 |.\code{_|_getstat|
|000012e0| 65 5f 5f 28 29 7d 20 6d | 65 74 68 6f 64 2c 20 74 |e__()} m|ethod, t|
|000012f0| 68 65 20 69 6e 73 74 61 | 6e 63 65 27 73 20 5c 63 |he insta|nce's \c|
|00001300| 6f 64 65 7b 5f 5f 64 69 | 63 74 5f 5f 7d 20 69 73 |ode{__di|ct__} is|
|00001310| 0a 70 69 63 6b 6c 65 64 | 2e 20 20 49 66 20 74 68 |.pickled|. If th|
|00001320| 65 72 65 20 69 73 20 6e | 6f 20 5c 63 6f 64 65 7b |ere is n|o \code{|
|00001330| 5f 5f 73 65 74 73 74 61 | 74 65 5f 5f 28 29 7d 20 |__setsta|te__()} |
|00001340| 6d 65 74 68 6f 64 2c 20 | 74 68 65 20 70 69 63 6b |method, |the pick|
|00001350| 6c 65 64 0a 6f 62 6a 65 | 63 74 20 6d 75 73 74 20 |led.obje|ct must |
|00001360| 62 65 20 61 20 64 69 63 | 74 69 6f 6e 61 72 79 20 |be a dic|tionary |
|00001370| 61 6e 64 20 69 74 73 20 | 69 74 65 6d 73 20 61 72 |and its |items ar|
|00001380| 65 20 61 73 73 69 67 6e | 65 64 20 74 6f 20 74 68 |e assign|ed to th|
|00001390| 65 20 6e 65 77 0a 69 6e | 73 74 61 6e 63 65 27 73 |e new.in|stance's|
|000013a0| 20 64 69 63 74 69 6f 6e | 61 72 79 2e 20 20 28 49 | diction|ary. (I|
|000013b0| 66 20 61 20 63 6c 61 73 | 73 20 64 65 66 69 6e 65 |f a clas|s define|
|000013c0| 73 20 62 6f 74 68 20 5c | 63 6f 64 65 7b 5f 5f 67 |s both \|code{__g|
|000013d0| 65 74 73 74 61 74 65 5f | 5f 28 29 7d 0a 61 6e 64 |etstate_|_()}.and|
|000013e0| 20 5c 63 6f 64 65 7b 5f | 5f 73 65 74 73 74 61 74 | \code{_|_setstat|
|000013f0| 65 5f 5f 28 29 7d 2c 20 | 74 68 65 20 73 74 61 74 |e__()}, |the stat|
|00001400| 65 20 6f 62 6a 65 63 74 | 20 6e 65 65 64 6e 27 74 |e object| needn't|
|00001410| 20 62 65 20 61 20 64 69 | 63 74 69 6f 6e 61 72 79 | be a di|ctionary|
|00001420| 0a 2d 2d 2d 20 74 68 65 | 73 65 20 6d 65 74 68 6f |.--- the|se metho|
|00001430| 64 73 20 63 61 6e 20 64 | 6f 20 77 68 61 74 20 74 |ds can d|o what t|
|00001440| 68 65 79 20 77 61 6e 74 | 2e 29 20 20 54 68 69 73 |hey want|.) This|
|00001450| 20 70 72 6f 74 6f 63 6f | 6c 20 69 73 20 61 6c 73 | protoco|l is als|
|00001460| 6f 20 75 73 65 64 0a 62 | 79 20 74 68 65 20 73 68 |o used.b|y the sh|
|00001470| 61 6c 6c 6f 77 20 61 6e | 64 20 64 65 65 70 20 63 |allow an|d deep c|
|00001480| 6f 70 79 69 6e 67 20 6f | 70 65 72 61 74 69 6f 6e |opying o|peration|
|00001490| 73 20 64 65 66 69 6e 65 | 64 20 69 6e 20 74 68 65 |s define|d in the|
|000014a0| 20 5c 63 6f 64 65 7b 63 | 6f 70 79 7d 0a 6d 6f 64 | \code{c|opy}.mod|
|000014b0| 75 6c 65 2e 0a 5c 74 74 | 69 6e 64 65 78 7b 5f 5f |ule..\tt|index{__|
|000014c0| 67 65 74 73 74 61 74 65 | 5f 5f 7d 0a 5c 74 74 69 |getstate|__}.\tti|
|000014d0| 6e 64 65 78 7b 5f 5f 73 | 65 74 73 74 61 74 65 5f |ndex{__s|etstate_|
|000014e0| 5f 7d 0a 5c 74 74 69 6e | 64 65 78 7b 5f 5f 64 69 |_}.\ttin|dex{__di|
|000014f0| 63 74 5f 5f 7d 0a 0a 4e | 6f 74 65 20 74 68 61 74 |ct__}..N|ote that|
|00001500| 20 77 68 65 6e 20 63 6c | 61 73 73 20 69 6e 73 74 | when cl|ass inst|
|00001510| 61 6e 63 65 73 20 61 72 | 65 20 70 69 63 6b 6c 65 |ances ar|e pickle|
|00001520| 64 2c 20 74 68 65 69 72 | 20 63 6c 61 73 73 27 73 |d, their| class's|
|00001530| 20 63 6f 64 65 20 61 6e | 64 0a 64 61 74 61 20 61 | code an|d.data a|
|00001540| 72 65 20 6e 6f 74 20 70 | 69 63 6b 6c 65 64 20 61 |re not p|ickled a|
|00001550| 6c 6f 6e 67 20 77 69 74 | 68 20 74 68 65 6d 2e 20 |long wit|h them. |
|00001560| 20 4f 6e 6c 79 20 74 68 | 65 20 69 6e 73 74 61 6e | Only th|e instan|
|00001570| 63 65 20 64 61 74 61 20 | 61 72 65 0a 70 69 63 6b |ce data |are.pick|
|00001580| 6c 65 64 2e 20 20 54 68 | 69 73 20 69 73 20 64 6f |led. Th|is is do|
|00001590| 6e 65 20 6f 6e 20 70 75 | 72 70 6f 73 65 2c 20 73 |ne on pu|rpose, s|
|000015a0| 6f 20 79 6f 75 20 63 61 | 6e 20 66 69 78 20 62 75 |o you ca|n fix bu|
|000015b0| 67 73 20 69 6e 20 61 20 | 63 6c 61 73 73 20 6f 72 |gs in a |class or|
|000015c0| 0a 61 64 64 20 6d 65 74 | 68 6f 64 73 20 61 6e 64 |.add met|hods and|
|000015d0| 20 73 74 69 6c 6c 20 6c | 6f 61 64 20 6f 62 6a 65 | still l|oad obje|
|000015e0| 63 74 73 20 74 68 61 74 | 20 77 65 72 65 20 63 72 |cts that| were cr|
|000015f0| 65 61 74 65 64 20 77 69 | 74 68 20 61 6e 20 65 61 |eated wi|th an ea|
|00001600| 72 6c 69 65 72 0a 76 65 | 72 73 69 6f 6e 20 6f 66 |rlier.ve|rsion of|
|00001610| 20 74 68 65 20 63 6c 61 | 73 73 2e 20 20 49 66 20 | the cla|ss. If |
|00001620| 79 6f 75 20 70 6c 61 6e | 20 74 6f 20 68 61 76 65 |you plan| to have|
|00001630| 20 6c 6f 6e 67 2d 6c 69 | 76 65 64 20 6f 62 6a 65 | long-li|ved obje|
|00001640| 63 74 73 20 74 68 61 74 | 0a 77 69 6c 6c 20 73 65 |cts that|.will se|
|00001650| 65 20 6d 61 6e 79 20 76 | 65 72 73 69 6f 6e 73 20 |e many v|ersions |
|00001660| 6f 66 20 61 20 63 6c 61 | 73 73 2c 20 69 74 20 6d |of a cla|ss, it m|
|00001670| 61 79 20 62 65 20 77 6f | 72 74 68 77 68 69 6c 65 |ay be wo|rthwhile|
|00001680| 20 74 6f 20 70 75 74 20 | 61 20 76 65 72 73 69 6f | to put |a versio|
|00001690| 6e 0a 6e 75 6d 62 65 72 | 20 69 6e 20 74 68 65 20 |n.number| in the |
|000016a0| 6f 62 6a 65 63 74 73 20 | 73 6f 20 74 68 61 74 20 |objects |so that |
|000016b0| 73 75 69 74 61 62 6c 65 | 20 63 6f 6e 76 65 72 73 |suitable| convers|
|000016c0| 69 6f 6e 73 20 63 61 6e | 20 62 65 20 6d 61 64 65 |ions can| be made|
|000016d0| 20 62 79 20 74 68 65 0a | 63 6c 61 73 73 27 73 20 | by the.|class's |
|000016e0| 5c 63 6f 64 65 7b 5f 5f | 73 65 74 73 74 61 74 65 |\code{__|setstate|
|000016f0| 5f 5f 28 29 7d 20 6d 65 | 74 68 6f 64 2e 0a 0a 57 |__()} me|thod...W|
|00001700| 68 65 6e 20 61 20 63 6c | 61 73 73 20 69 74 73 65 |hen a cl|ass itse|
|00001710| 6c 66 20 69 73 20 70 69 | 63 6b 6c 65 64 2c 20 6f |lf is pi|ckled, o|
|00001720| 6e 6c 79 20 69 74 73 20 | 6e 61 6d 65 20 69 73 20 |nly its |name is |
|00001730| 70 69 63 6b 6c 65 64 20 | 2d 2d 2d 20 74 68 65 20 |pickled |--- the |
|00001740| 63 6c 61 73 73 0a 64 65 | 66 69 6e 69 74 69 6f 6e |class.de|finition|
|00001750| 20 69 73 20 6e 6f 74 20 | 70 69 63 6b 6c 65 64 2c | is not |pickled,|
|00001760| 20 62 75 74 20 72 65 2d | 69 6d 70 6f 72 74 65 64 | but re-|imported|
|00001770| 20 62 79 20 74 68 65 20 | 75 6e 70 69 63 6b 6c 69 | by the |unpickli|
|00001780| 6e 67 20 70 72 6f 63 65 | 73 73 2e 0a 54 68 65 72 |ng proce|ss..Ther|
|00001790| 65 66 6f 72 65 2c 20 74 | 68 65 20 72 65 73 74 72 |efore, t|he restr|
|000017a0| 69 63 74 69 6f 6e 20 74 | 68 61 74 20 74 68 65 20 |iction t|hat the |
|000017b0| 63 6c 61 73 73 20 6d 75 | 73 74 20 62 65 20 64 65 |class mu|st be de|
|000017c0| 66 69 6e 65 64 20 61 74 | 20 74 68 65 20 74 6f 70 |fined at| the top|
|000017d0| 0a 6c 65 76 65 6c 20 69 | 6e 20 61 20 6d 6f 64 75 |.level i|n a modu|
|000017e0| 6c 65 20 61 70 70 6c 69 | 65 73 20 74 6f 20 70 69 |le appli|es to pi|
|000017f0| 63 6b 6c 65 64 20 63 6c | 61 73 73 65 73 20 61 73 |ckled cl|asses as|
|00001800| 20 77 65 6c 6c 2e 0a 0a | 5c 72 65 6e 65 77 63 6f | well...|\renewco|
|00001810| 6d 6d 61 6e 64 7b 5c 69 | 6e 64 65 78 73 75 62 69 |mmand{\i|ndexsubi|
|00001820| 74 65 6d 7d 7b 28 69 6e | 20 6d 6f 64 75 6c 65 20 |tem}{(in| module |
|00001830| 70 69 63 6b 6c 65 29 7d | 0a 0a 54 68 65 20 69 6e |pickle)}|..The in|
|00001840| 74 65 72 66 61 63 65 20 | 63 61 6e 20 62 65 20 73 |terface |can be s|
|00001850| 75 6d 6d 61 72 69 7a 65 | 64 20 61 73 20 66 6f 6c |ummarize|d as fol|
|00001860| 6c 6f 77 73 2e 0a 0a 54 | 6f 20 70 69 63 6b 6c 65 |lows...T|o pickle|
|00001870| 20 61 6e 20 6f 62 6a 65 | 63 74 20 5c 63 6f 64 65 | an obje|ct \code|
|00001880| 7b 78 7d 20 6f 6e 74 6f | 20 61 20 66 69 6c 65 20 |{x} onto| a file |
|00001890| 5c 63 6f 64 65 7b 66 7d | 2c 20 6f 70 65 6e 20 66 |\code{f}|, open f|
|000018a0| 6f 72 20 77 72 69 74 69 | 6e 67 3a 0a 0a 5c 62 65 |or writi|ng:..\be|
|000018b0| 67 69 6e 7b 76 65 72 62 | 61 74 69 6d 7d 0a 70 20 |gin{verb|atim}.p |
|000018c0| 3d 20 70 69 63 6b 6c 65 | 2e 50 69 63 6b 6c 65 72 |= pickle|.Pickler|
|000018d0| 28 66 29 0a 70 2e 64 75 | 6d 70 28 78 29 0a 5c 65 |(f).p.du|mp(x).\e|
|000018e0| 6e 64 7b 76 65 72 62 61 | 74 69 6d 7d 0a 0a 41 20 |nd{verba|tim}..A |
|000018f0| 73 68 6f 72 74 68 61 6e | 64 20 66 6f 72 20 74 68 |shorthan|d for th|
|00001900| 69 73 20 69 73 3a 0a 0a | 5c 62 65 67 69 6e 7b 76 |is is:..|\begin{v|
|00001910| 65 72 62 61 74 69 6d 7d | 0a 70 69 63 6b 6c 65 2e |erbatim}|.pickle.|
|00001920| 64 75 6d 70 28 78 2c 20 | 66 29 0a 5c 65 6e 64 7b |dump(x, |f).\end{|
|00001930| 76 65 72 62 61 74 69 6d | 7d 0a 0a 54 6f 20 75 6e |verbatim|}..To un|
|00001940| 70 69 63 6b 6c 65 20 61 | 6e 20 6f 62 6a 65 63 74 |pickle a|n object|
|00001950| 20 5c 63 6f 64 65 7b 78 | 7d 20 66 72 6f 6d 20 61 | \code{x|} from a|
|00001960| 20 66 69 6c 65 20 5c 63 | 6f 64 65 7b 66 7d 2c 20 | file \c|ode{f}, |
|00001970| 6f 70 65 6e 20 66 6f 72 | 20 72 65 61 64 69 6e 67 |open for| reading|
|00001980| 3a 0a 0a 5c 62 65 67 69 | 6e 7b 76 65 72 62 61 74 |:..\begi|n{verbat|
|00001990| 69 6d 7d 0a 75 20 3d 20 | 70 69 63 6b 6c 65 2e 55 |im}.u = |pickle.U|
|000019a0| 6e 70 69 63 6b 6c 65 72 | 28 66 29 0a 78 20 3d 20 |npickler|(f).x = |
|000019b0| 75 2e 6c 6f 61 64 28 29 | 0a 5c 65 6e 64 7b 76 65 |u.load()|.\end{ve|
|000019c0| 72 62 61 74 69 6d 7d 0a | 0a 41 20 73 68 6f 72 74 |rbatim}.|.A short|
|000019d0| 68 61 6e 64 20 69 73 3a | 0a 0a 5c 62 65 67 69 6e |hand is:|..\begin|
|000019e0| 7b 76 65 72 62 61 74 69 | 6d 7d 0a 78 20 3d 20 70 |{verbati|m}.x = p|
|000019f0| 69 63 6b 6c 65 2e 6c 6f | 61 64 28 66 29 0a 5c 65 |ickle.lo|ad(f).\e|
|00001a00| 6e 64 7b 76 65 72 62 61 | 74 69 6d 7d 0a 0a 54 68 |nd{verba|tim}..Th|
|00001a10| 65 20 5c 63 6f 64 65 7b | 50 69 63 6b 6c 65 72 7d |e \code{|Pickler}|
|00001a20| 20 63 6c 61 73 73 20 6f | 6e 6c 79 20 63 61 6c 6c | class o|nly call|
|00001a30| 73 20 74 68 65 20 6d 65 | 74 68 6f 64 20 5c 63 6f |s the me|thod \co|
|00001a40| 64 65 7b 66 2e 77 72 69 | 74 65 7d 20 77 69 74 68 |de{f.wri|te} with|
|00001a50| 20 61 0a 73 74 72 69 6e | 67 20 61 72 67 75 6d 65 | a.strin|g argume|
|00001a60| 6e 74 2e 20 20 54 68 65 | 20 5c 63 6f 64 65 7b 55 |nt. The| \code{U|
|00001a70| 6e 70 69 63 6b 6c 65 72 | 7d 20 63 61 6c 6c 73 20 |npickler|} calls |
|00001a80| 74 68 65 20 6d 65 74 68 | 6f 64 73 20 5c 63 6f 64 |the meth|ods \cod|
|00001a90| 65 7b 66 2e 72 65 61 64 | 7d 0a 28 77 69 74 68 20 |e{f.read|}.(with |
|00001aa0| 61 6e 20 69 6e 74 65 67 | 65 72 20 61 72 67 75 6d |an integ|er argum|
|00001ab0| 65 6e 74 29 20 61 6e 64 | 20 5c 63 6f 64 65 7b 66 |ent) and| \code{f|
|00001ac0| 2e 72 65 61 64 6c 69 6e | 65 7d 20 28 77 69 74 68 |.readlin|e} (with|
|00001ad0| 6f 75 74 20 61 72 67 75 | 6d 65 6e 74 29 2c 0a 62 |out argu|ment),.b|
|00001ae0| 6f 74 68 20 72 65 74 75 | 72 6e 69 6e 67 20 61 20 |oth retu|rning a |
|00001af0| 73 74 72 69 6e 67 2e 20 | 20 49 74 20 69 73 20 65 |string. | It is e|
|00001b00| 78 70 6c 69 63 69 74 6c | 79 20 61 6c 6c 6f 77 65 |xplicitl|y allowe|
|00001b10| 64 20 74 6f 20 70 61 73 | 73 20 6e 6f 6e 2d 66 69 |d to pas|s non-fi|
|00001b20| 6c 65 0a 6f 62 6a 65 63 | 74 73 20 68 65 72 65 2c |le.objec|ts here,|
|00001b30| 20 61 73 20 6c 6f 6e 67 | 20 61 73 20 74 68 65 79 | as long| as they|
|00001b40| 20 68 61 76 65 20 74 68 | 65 20 72 69 67 68 74 20 | have th|e right |
|00001b50| 6d 65 74 68 6f 64 73 2e | 0a 5c 74 74 69 6e 64 65 |methods.|.\ttinde|
|00001b60| 78 7b 55 6e 70 69 63 6b | 6c 65 72 7d 0a 5c 74 74 |x{Unpick|ler}.\tt|
|00001b70| 69 6e 64 65 78 7b 50 69 | 63 6b 6c 65 72 7d 0a 0a |index{Pi|ckler}..|
|00001b80| 54 68 65 20 66 6f 6c 6c | 6f 77 69 6e 67 20 74 79 |The foll|owing ty|
|00001b90| 70 65 73 20 63 61 6e 20 | 62 65 20 70 69 63 6b 6c |pes can |be pickl|
|00001ba0| 65 64 3a 0a 5c 62 65 67 | 69 6e 7b 69 74 65 6d 69 |ed:.\beg|in{itemi|
|00001bb0| 7a 65 7d 0a 0a 5c 69 74 | 65 6d 20 5c 63 6f 64 65 |ze}..\it|em \code|
|00001bc0| 7b 4e 6f 6e 65 7d 0a 0a | 5c 69 74 65 6d 20 69 6e |{None}..|\item in|
|00001bd0| 74 65 67 65 72 73 2c 20 | 6c 6f 6e 67 20 69 6e 74 |tegers, |long int|
|00001be0| 65 67 65 72 73 2c 20 66 | 6c 6f 61 74 69 6e 67 20 |egers, f|loating |
|00001bf0| 70 6f 69 6e 74 20 6e 75 | 6d 62 65 72 73 0a 0a 5c |point nu|mbers..\|
|00001c00| 69 74 65 6d 20 73 74 72 | 69 6e 67 73 0a 0a 5c 69 |item str|ings..\i|
|00001c10| 74 65 6d 20 74 75 70 6c | 65 73 2c 20 6c 69 73 74 |tem tupl|es, list|
|00001c20| 73 20 61 6e 64 20 64 69 | 63 74 69 6f 6e 61 72 69 |s and di|ctionari|
|00001c30| 65 73 20 63 6f 6e 74 61 | 69 6e 69 6e 67 20 6f 6e |es conta|ining on|
|00001c40| 6c 79 20 70 69 63 6b 6c | 61 62 6c 65 20 6f 62 6a |ly pickl|able obj|
|00001c50| 65 63 74 73 0a 0a 5c 69 | 74 65 6d 20 63 6c 61 73 |ects..\i|tem clas|
|00001c60| 73 65 73 20 74 68 61 74 | 20 61 72 65 20 64 65 66 |ses that| are def|
|00001c70| 69 6e 65 64 20 61 74 20 | 74 68 65 20 74 6f 70 20 |ined at |the top |
|00001c80| 6c 65 76 65 6c 20 69 6e | 20 61 20 6d 6f 64 75 6c |level in| a modul|
|00001c90| 65 0a 0a 5c 69 74 65 6d | 20 69 6e 73 74 61 6e 63 |e..\item| instanc|
|00001ca0| 65 73 20 6f 66 20 73 75 | 63 68 20 63 6c 61 73 73 |es of su|ch class|
|00001cb0| 65 73 20 77 68 6f 73 65 | 20 5c 63 6f 64 65 7b 5f |es whose| \code{_|
|00001cc0| 5f 64 69 63 74 5f 5f 7d | 20 6f 72 0a 5c 63 6f 64 |_dict__}| or.\cod|
|00001cd0| 65 7b 5f 5f 73 65 74 73 | 74 61 74 65 5f 5f 28 29 |e{__sets|tate__()|
|00001ce0| 7d 20 69 73 20 70 69 63 | 6b 6c 61 62 6c 65 0a 0a |} is pic|klable..|
|00001cf0| 5c 65 6e 64 7b 69 74 65 | 6d 69 7a 65 7d 0a 0a 41 |\end{ite|mize}..A|
|00001d00| 74 74 65 6d 70 74 73 20 | 74 6f 20 70 69 63 6b 6c |ttempts |to pickl|
|00001d10| 65 20 75 6e 70 69 63 6b | 6c 61 62 6c 65 20 6f 62 |e unpick|lable ob|
|00001d20| 6a 65 63 74 73 20 77 69 | 6c 6c 20 72 61 69 73 65 |jects wi|ll raise|
|00001d30| 20 74 68 65 0a 5c 63 6f | 64 65 7b 50 69 63 6b 6c | the.\co|de{Pickl|
|00001d40| 69 6e 67 45 72 72 6f 72 | 7d 20 65 78 63 65 70 74 |ingError|} except|
|00001d50| 69 6f 6e 3b 20 77 68 65 | 6e 20 74 68 69 73 20 68 |ion; whe|n this h|
|00001d60| 61 70 70 65 6e 73 2c 20 | 61 6e 20 75 6e 73 70 65 |appens, |an unspe|
|00001d70| 63 69 66 69 65 64 0a 6e | 75 6d 62 65 72 20 6f 66 |cified.n|umber of|
|00001d80| 20 62 79 74 65 73 20 6d | 61 79 20 68 61 76 65 20 | bytes m|ay have |
|00001d90| 62 65 65 6e 20 77 72 69 | 74 74 65 6e 20 74 6f 20 |been wri|tten to |
|00001da0| 74 68 65 20 66 69 6c 65 | 2e 0a 0a 49 74 20 69 73 |the file|...It is|
|00001db0| 20 70 6f 73 73 69 62 6c | 65 20 74 6f 20 6d 61 6b | possibl|e to mak|
|00001dc0| 65 20 6d 75 6c 74 69 70 | 6c 65 20 63 61 6c 6c 73 |e multip|le calls|
|00001dd0| 20 74 6f 20 74 68 65 20 | 5c 63 6f 64 65 7b 64 75 | to the |\code{du|
|00001de0| 6d 70 28 29 7d 20 6d 65 | 74 68 6f 64 20 6f 66 0a |mp()} me|thod of.|
|00001df0| 74 68 65 20 73 61 6d 65 | 20 5c 63 6f 64 65 7b 50 |the same| \code{P|
|00001e00| 69 63 6b 6c 65 72 7d 20 | 69 6e 73 74 61 6e 63 65 |ickler} |instance|
|00001e10| 2e 20 20 54 68 65 73 65 | 20 6d 75 73 74 20 74 68 |. These| must th|
|00001e20| 65 6e 20 62 65 20 6d 61 | 74 63 68 65 64 20 74 6f |en be ma|tched to|
|00001e30| 20 74 68 65 0a 73 61 6d | 65 20 6e 75 6d 62 65 72 | the.sam|e number|
|00001e40| 20 6f 66 20 63 61 6c 6c | 73 20 74 6f 20 74 68 65 | of call|s to the|
|00001e50| 20 5c 63 6f 64 65 7b 6c | 6f 61 64 28 29 7d 20 69 | \code{l|oad()} i|
|00001e60| 6e 73 74 61 6e 63 65 20 | 6f 66 20 74 68 65 0a 63 |nstance |of the.c|
|00001e70| 6f 72 72 65 73 70 6f 6e | 64 69 6e 67 20 5c 63 6f |orrespon|ding \co|
|00001e80| 64 65 7b 55 6e 70 69 63 | 6b 6c 65 72 7d 20 69 6e |de{Unpic|kler} in|
|00001e90| 73 74 61 6e 63 65 2e 20 | 20 49 66 20 74 68 65 20 |stance. | If the |
|00001ea0| 73 61 6d 65 20 6f 62 6a | 65 63 74 20 69 73 0a 70 |same obj|ect is.p|
|00001eb0| 69 63 6b 6c 65 64 20 62 | 79 20 6d 75 6c 74 69 70 |ickled b|y multip|
|00001ec0| 6c 65 20 5c 63 6f 64 65 | 7b 64 75 6d 70 28 29 7d |le \code|{dump()}|
|00001ed0| 20 63 61 6c 6c 73 2c 20 | 74 68 65 20 5c 63 6f 64 | calls, |the \cod|
|00001ee0| 65 7b 6c 6f 61 64 28 29 | 7d 20 77 69 6c 6c 20 61 |e{load()|} will a|
|00001ef0| 6c 6c 0a 79 69 65 6c 64 | 20 72 65 66 65 72 65 6e |ll.yield| referen|
|00001f00| 63 65 73 20 74 6f 20 74 | 68 65 20 73 61 6d 65 20 |ces to t|he same |
|00001f10| 6f 62 6a 65 63 74 2e 20 | 20 7b 5c 65 6d 20 57 61 |object. | {\em Wa|
|00001f20| 72 6e 69 6e 67 7d 3a 20 | 74 68 69 73 20 69 73 20 |rning}: |this is |
|00001f30| 69 6e 74 65 6e 64 65 64 | 0a 66 6f 72 20 70 69 63 |intended|.for pic|
|00001f40| 6b 6c 69 6e 67 20 6d 75 | 6c 74 69 70 6c 65 20 6f |kling mu|ltiple o|
|00001f50| 62 6a 65 63 74 73 20 77 | 69 74 68 6f 75 74 20 69 |bjects w|ithout i|
|00001f60| 6e 74 65 72 76 65 6e 69 | 6e 67 20 6d 6f 64 69 66 |nterveni|ng modif|
|00001f70| 69 63 61 74 69 6f 6e 73 | 20 74 6f 20 74 68 65 0a |ications| to the.|
|00001f80| 6f 62 6a 65 63 74 73 20 | 6f 72 20 74 68 65 69 72 |objects |or their|
|00001f90| 20 70 61 72 74 73 2e 20 | 20 49 66 20 79 6f 75 20 | parts. | If you |
|00001fa0| 6d 6f 64 69 66 79 20 61 | 6e 20 6f 62 6a 65 63 74 |modify a|n object|
|00001fb0| 20 61 6e 64 20 74 68 65 | 6e 20 70 69 63 6b 6c 65 | and the|n pickle|
|00001fc0| 20 69 74 0a 61 67 61 69 | 6e 20 75 73 69 6e 67 20 | it.agai|n using |
|00001fd0| 74 68 65 20 73 61 6d 65 | 20 5c 63 6f 64 65 7b 50 |the same| \code{P|
|00001fe0| 69 63 6b 6c 65 72 7d 20 | 69 6e 73 74 61 6e 63 65 |ickler} |instance|
|00001ff0| 2c 20 74 68 65 20 6f 62 | 6a 65 63 74 20 69 73 20 |, the ob|ject is |
|00002000| 6e 6f 74 0a 70 69 63 6b | 6c 65 64 20 61 67 61 69 |not.pick|led agai|
|00002010| 6e 20 2d 2d 2d 20 61 20 | 72 65 66 65 72 65 6e 63 |n --- a |referenc|
|00002020| 65 20 74 6f 20 69 74 20 | 69 73 20 70 69 63 6b 6c |e to it |is pickl|
|00002030| 65 64 20 61 6e 64 20 74 | 68 65 0a 5c 63 6f 64 65 |ed and t|he.\code|
|00002040| 7b 55 6e 70 69 63 6b 6c | 65 72 7d 20 77 69 6c 6c |{Unpickl|er} will|
|00002050| 20 72 65 74 75 72 6e 20 | 74 68 65 20 6f 6c 64 20 | return |the old |
|00002060| 76 61 6c 75 65 2c 20 6e | 6f 74 20 74 68 65 20 6d |value, n|ot the m|
|00002070| 6f 64 69 66 69 65 64 20 | 6f 6e 65 2e 0a 28 54 68 |odified |one..(Th|
|00002080| 65 72 65 20 61 72 65 20 | 74 77 6f 20 70 72 6f 62 |ere are |two prob|
|00002090| 6c 65 6d 73 20 68 65 72 | 65 3a 20 28 61 29 20 64 |lems her|e: (a) d|
|000020a0| 65 74 65 63 74 69 6e 67 | 20 63 68 61 6e 67 65 73 |etecting| changes|
|000020b0| 2c 20 61 6e 64 20 28 62 | 29 0a 6d 61 72 73 68 61 |, and (b|).marsha|
|000020c0| 6c 6c 69 6e 67 20 61 20 | 6d 69 6e 69 6d 61 6c 20 |lling a |minimal |
|000020d0| 73 65 74 20 6f 66 20 63 | 68 61 6e 67 65 73 2e 20 |set of c|hanges. |
|000020e0| 20 49 20 68 61 76 65 20 | 6e 6f 20 61 6e 73 77 65 | I have |no answe|
|000020f0| 72 73 2e 20 20 47 61 72 | 62 61 67 65 0a 43 6f 6c |rs. Gar|bage.Col|
|00002100| 6c 65 63 74 69 6f 6e 20 | 6d 61 79 20 61 6c 73 6f |lection |may also|
|00002110| 20 62 65 63 6f 6d 65 20 | 61 20 70 72 6f 62 6c 65 | become |a proble|
|00002120| 6d 20 68 65 72 65 2e 29 | 0a 0a 41 70 61 72 74 20 |m here.)|..Apart |
|00002130| 66 72 6f 6d 20 74 68 65 | 20 5c 63 6f 64 65 7b 50 |from the| \code{P|
|00002140| 69 63 6b 6c 65 72 7d 20 | 61 6e 64 20 5c 63 6f 64 |ickler} |and \cod|
|00002150| 65 7b 55 6e 70 69 63 6b | 6c 65 72 7d 20 63 6c 61 |e{Unpick|ler} cla|
|00002160| 73 73 65 73 2c 20 74 68 | 65 0a 6d 6f 64 75 6c 65 |sses, th|e.module|
|00002170| 20 64 65 66 69 6e 65 73 | 20 74 68 65 20 66 6f 6c | defines| the fol|
|00002180| 6c 6f 77 69 6e 67 20 66 | 75 6e 63 74 69 6f 6e 73 |lowing f|unctions|
|00002190| 2c 20 61 6e 64 20 61 6e | 20 65 78 63 65 70 74 69 |, and an| excepti|
|000021a0| 6f 6e 3a 0a 0a 5c 62 65 | 67 69 6e 7b 66 75 6e 63 |on:..\be|gin{func|
|000021b0| 64 65 73 63 7d 7b 64 75 | 6d 70 7d 7b 6f 62 6a 65 |desc}{du|mp}{obje|
|000021c0| 63 74 5c 2c 20 66 69 6c | 65 7d 0a 57 72 69 74 65 |ct\, fil|e}.Write|
|000021d0| 20 61 20 70 69 63 6b 6c | 65 64 20 72 65 70 72 65 | a pickl|ed repre|
|000021e0| 73 65 6e 74 61 74 69 6f | 6e 20 6f 66 20 5c 76 61 |sentatio|n of \va|
|000021f0| 72 7b 6f 62 65 63 74 7d | 20 74 6f 20 74 68 65 20 |r{obect}| to the |
|00002200| 6f 70 65 6e 20 66 69 6c | 65 20 6f 62 6a 65 63 74 |open fil|e object|
|00002210| 0a 5c 76 61 72 7b 66 69 | 6c 65 7d 2e 20 20 54 68 |.\var{fi|le}. Th|
|00002220| 69 73 20 69 73 20 65 71 | 75 69 76 61 6c 65 6e 74 |is is eq|uivalent|
|00002230| 20 74 6f 20 5c 63 6f 64 | 65 7b 50 69 63 6b 6c 65 | to \cod|e{Pickle|
|00002240| 72 28 66 69 6c 65 29 2e | 64 75 6d 70 28 6f 62 6a |r(file).|dump(obj|
|00002250| 65 63 74 29 7d 2e 0a 5c | 65 6e 64 7b 66 75 6e 63 |ect)}..\|end{func|
|00002260| 64 65 73 63 7d 0a 0a 5c | 62 65 67 69 6e 7b 66 75 |desc}..\|begin{fu|
|00002270| 6e 63 64 65 73 63 7d 7b | 6c 6f 61 64 7d 7b 66 69 |ncdesc}{|load}{fi|
|00002280| 6c 65 7d 0a 52 65 61 64 | 20 61 20 70 69 63 6b 6c |le}.Read| a pickl|
|00002290| 65 64 20 6f 62 6a 65 63 | 74 20 66 72 6f 6d 20 74 |ed objec|t from t|
|000022a0| 68 65 20 6f 70 65 6e 20 | 66 69 6c 65 20 6f 62 6a |he open |file obj|
|000022b0| 65 63 74 20 5c 76 61 72 | 7b 66 69 6c 65 7d 2e 20 |ect \var|{file}. |
|000022c0| 20 54 68 69 73 20 69 73 | 0a 65 71 75 69 76 61 6c | This is|.equival|
|000022d0| 65 6e 74 20 74 6f 20 5c | 63 6f 64 65 7b 55 6e 70 |ent to \|code{Unp|
|000022e0| 69 63 6b 6c 65 72 28 66 | 69 6c 65 29 2e 6c 6f 61 |ickler(f|ile).loa|
|000022f0| 64 28 29 7d 2e 0a 5c 65 | 6e 64 7b 66 75 6e 63 64 |d()}..\e|nd{funcd|
|00002300| 65 73 63 7d 0a 0a 5c 62 | 65 67 69 6e 7b 66 75 6e |esc}..\b|egin{fun|
|00002310| 63 64 65 73 63 7d 7b 64 | 75 6d 70 73 7d 7b 6f 62 |cdesc}{d|umps}{ob|
|00002320| 6a 65 63 74 7d 0a 52 65 | 74 75 72 6e 20 74 68 65 |ject}.Re|turn the|
|00002330| 20 70 69 63 6b 6c 65 64 | 20 72 65 70 72 65 73 65 | pickled| represe|
|00002340| 6e 74 61 74 69 6f 6e 20 | 6f 66 20 74 68 65 20 6f |ntation |of the o|
|00002350| 62 6a 65 63 74 20 61 73 | 20 61 20 73 74 72 69 6e |bject as| a strin|
|00002360| 67 2c 20 69 6e 73 74 65 | 61 64 0a 6f 66 20 77 72 |g, inste|ad.of wr|
|00002370| 69 74 69 6e 67 20 69 74 | 20 74 6f 20 61 20 66 69 |iting it| to a fi|
|00002380| 6c 65 2e 0a 5c 65 6e 64 | 7b 66 75 6e 63 64 65 73 |le..\end|{funcdes|
|00002390| 63 7d 0a 0a 5c 62 65 67 | 69 6e 7b 66 75 6e 63 64 |c}..\beg|in{funcd|
|000023a0| 65 73 63 7d 7b 6c 6f 61 | 64 73 7d 7b 73 74 72 69 |esc}{loa|ds}{stri|
|000023b0| 6e 67 7d 0a 52 65 61 64 | 20 61 20 70 69 63 6b 6c |ng}.Read| a pickl|
|000023c0| 65 64 20 6f 62 6a 65 63 | 74 20 66 72 6f 6d 20 61 |ed objec|t from a|
|000023d0| 20 73 74 72 69 6e 67 20 | 69 6e 73 74 65 61 64 20 | string |instead |
|000023e0| 6f 66 20 61 20 66 69 6c | 65 2e 20 20 43 68 61 72 |of a fil|e. Char|
|000023f0| 61 63 74 65 72 73 20 69 | 6e 0a 74 68 65 20 73 74 |acters i|n.the st|
|00002400| 72 69 6e 67 20 70 61 73 | 74 20 74 68 65 20 70 69 |ring pas|t the pi|
|00002410| 63 6b 6c 65 64 20 6f 62 | 6a 65 63 74 27 73 20 72 |ckled ob|ject's r|
|00002420| 65 70 72 65 73 65 6e 74 | 61 74 69 6f 6e 20 61 72 |epresent|ation ar|
|00002430| 65 20 69 67 6e 6f 72 65 | 64 2e 0a 5c 65 6e 64 7b |e ignore|d..\end{|
|00002440| 66 75 6e 63 64 65 73 63 | 7d 0a 0a 5c 62 65 67 69 |funcdesc|}..\begi|
|00002450| 6e 7b 65 78 63 64 65 73 | 63 7d 7b 50 69 63 6b 6c |n{excdes|c}{Pickl|
|00002460| 69 6e 67 45 72 72 6f 72 | 7d 0a 54 68 69 73 20 65 |ingError|}.This e|
|00002470| 78 63 65 70 74 69 6f 6e | 20 69 73 20 72 61 69 73 |xception| is rais|
|00002480| 65 64 20 77 68 65 6e 20 | 61 6e 20 75 6e 70 69 63 |ed when |an unpic|
|00002490| 6b 6c 61 62 6c 65 20 6f | 62 6a 65 63 74 20 69 73 |klable o|bject is|
|000024a0| 20 70 61 73 73 65 64 20 | 74 6f 0a 5c 63 6f 64 65 | passed |to.\code|
|000024b0| 7b 50 69 63 6b 6c 65 72 | 2e 64 75 6d 70 28 29 7d |{Pickler|.dump()}|
|000024c0| 2e 0a 5c 65 6e 64 7b 65 | 78 63 64 65 73 63 7d 0a |..\end{e|xcdesc}.|
+--------+-------------------------+-------------------------+--------+--------+