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
| Python script text executable
| default (weak)
| |
98%
| 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 42 75 69 6c 74 2d 69 |\section|{Built-i|
|00000010| 6e 20 4d 6f 64 75 6c 65 | 20 5c 73 65 63 74 63 6f |n Module| \sectco|
|00000020| 64 65 7b 69 6d 70 7d 7d | 0a 5c 62 69 6d 6f 64 69 |de{imp}}|.\bimodi|
|00000030| 6e 64 65 78 7b 69 6d 70 | 7d 0a 5c 69 6e 64 65 78 |ndex{imp|}.\index|
|00000040| 7b 69 6d 70 6f 72 74 7d | 0a 0a 54 68 69 73 20 6d |{import}|..This m|
|00000050| 6f 64 75 6c 65 20 70 72 | 6f 76 69 64 65 73 20 61 |odule pr|ovides a|
|00000060| 6e 20 69 6e 74 65 72 66 | 61 63 65 20 74 6f 20 74 |n interf|ace to t|
|00000070| 68 65 20 6d 65 63 68 61 | 6e 69 73 6d 73 20 75 73 |he mecha|nisms us|
|00000080| 65 64 20 74 6f 20 69 6d | 70 6c 65 6d 65 6e 74 0a |ed to im|plement.|
|00000090| 74 68 65 20 5c 63 6f 64 | 65 7b 69 6d 70 6f 72 74 |the \cod|e{import|
|000000a0| 7d 20 73 74 61 74 65 6d | 65 6e 74 2e 20 20 49 74 |} statem|ent. It|
|000000b0| 20 64 65 66 69 6e 65 73 | 20 74 68 65 20 66 6f 6c | defines| the fol|
|000000c0| 6c 6f 77 69 6e 67 20 63 | 6f 6e 73 74 61 6e 74 73 |lowing c|onstants|
|000000d0| 20 61 6e 64 0a 66 75 6e | 63 74 69 6f 6e 73 3a 0a | and.fun|ctions:.|
|000000e0| 0a 5c 72 65 6e 65 77 63 | 6f 6d 6d 61 6e 64 7b 5c |.\renewc|ommand{\|
|000000f0| 69 6e 64 65 78 73 75 62 | 69 74 65 6d 7d 7b 28 69 |indexsub|item}{(i|
|00000100| 6e 20 6d 6f 64 75 6c 65 | 20 69 6d 70 29 7d 0a 0a |n module| imp)}..|
|00000110| 5c 62 65 67 69 6e 7b 66 | 75 6e 63 64 65 73 63 7d |\begin{f|uncdesc}|
|00000120| 7b 67 65 74 5f 6d 61 67 | 69 63 7d 7b 7d 0a 52 65 |{get_mag|ic}{}.Re|
|00000130| 74 75 72 6e 20 74 68 65 | 20 6d 61 67 69 63 20 73 |turn the| magic s|
|00000140| 74 72 69 6e 67 20 76 61 | 6c 75 65 20 75 73 65 64 |tring va|lue used|
|00000150| 20 74 6f 20 72 65 63 6f | 67 6e 69 7a 65 20 62 79 | to reco|gnize by|
|00000160| 74 65 2d 63 6f 6d 70 69 | 6c 65 64 20 63 6f 64 65 |te-compi|led code|
|00000170| 0a 66 69 6c 65 73 20 28 | 60 60 5c 63 6f 64 65 7b |.files (|``\code{|
|00000180| 2e 70 79 63 7d 20 66 69 | 6c 65 73 27 27 29 2e 0a |.pyc} fi|les'')..|
|00000190| 5c 65 6e 64 7b 66 75 6e | 63 64 65 73 63 7d 0a 0a |\end{fun|cdesc}..|
|000001a0| 5c 62 65 67 69 6e 7b 66 | 75 6e 63 64 65 73 63 7d |\begin{f|uncdesc}|
|000001b0| 7b 67 65 74 5f 73 75 66 | 66 69 78 65 73 7d 7b 7d |{get_suf|fixes}{}|
|000001c0| 0a 52 65 74 75 72 6e 20 | 61 20 6c 69 73 74 20 6f |.Return |a list o|
|000001d0| 66 20 74 72 69 70 6c 65 | 73 2c 20 65 61 63 68 20 |f triple|s, each |
|000001e0| 64 65 73 63 72 69 62 69 | 6e 67 20 61 20 70 61 72 |describi|ng a par|
|000001f0| 74 69 63 75 6c 61 72 20 | 74 79 70 65 20 6f 66 20 |ticular |type of |
|00000200| 66 69 6c 65 2e 0a 45 61 | 63 68 20 74 72 69 70 6c |file..Ea|ch tripl|
|00000210| 65 20 68 61 73 20 74 68 | 65 20 66 6f 72 6d 20 5c |e has th|e form \|
|00000220| 63 6f 64 65 7b 28 5c 76 | 61 72 7b 73 75 66 66 69 |code{(\v|ar{suffi|
|00000230| 78 7d 2c 20 5c 76 61 72 | 7b 6d 6f 64 65 7d 2c 0a |x}, \var|{mode},.|
|00000240| 5c 76 61 72 7b 74 79 70 | 65 7d 29 7d 2c 20 77 68 |\var{typ|e})}, wh|
|00000250| 65 72 65 20 5c 76 61 72 | 7b 73 75 66 66 69 78 7d |ere \var|{suffix}|
|00000260| 20 69 73 20 61 20 73 74 | 72 69 6e 67 20 74 6f 20 | is a st|ring to |
|00000270| 62 65 20 61 70 70 65 6e | 64 65 64 20 74 6f 20 74 |be appen|ded to t|
|00000280| 68 65 0a 6d 6f 64 75 6c | 65 20 6e 61 6d 65 20 74 |he.modul|e name t|
|00000290| 6f 20 66 6f 72 6d 20 74 | 68 65 20 66 69 6c 65 6e |o form t|he filen|
|000002a0| 61 6d 65 20 74 6f 20 73 | 65 61 72 63 68 20 66 6f |ame to s|earch fo|
|000002b0| 72 2c 20 5c 76 61 72 7b | 6d 6f 64 65 7d 20 69 73 |r, \var{|mode} is|
|000002c0| 20 74 68 65 20 6d 6f 64 | 65 0a 73 74 72 69 6e 67 | the mod|e.string|
|000002d0| 20 74 6f 20 70 61 73 73 | 20 74 6f 20 74 68 65 20 | to pass| to the |
|000002e0| 62 75 69 6c 74 2d 69 6e | 20 5c 63 6f 64 65 7b 6f |built-in| \code{o|
|000002f0| 70 65 6e 7d 20 66 75 6e | 63 74 69 6f 6e 20 74 6f |pen} fun|ction to|
|00000300| 20 6f 70 65 6e 20 74 68 | 65 20 66 69 6c 65 0a 28 | open th|e file.(|
|00000310| 74 68 69 73 20 63 61 6e | 20 62 65 20 5c 63 6f 64 |this can| be \cod|
|00000320| 65 7b 27 72 27 7d 20 66 | 6f 72 20 74 65 78 74 20 |e{'r'} f|or text |
|00000330| 66 69 6c 65 73 20 6f 72 | 20 5c 63 6f 64 65 7b 27 |files or| \code{'|
|00000340| 72 62 27 7d 20 66 6f 72 | 20 62 69 6e 61 72 79 0a |rb'} for| binary.|
|00000350| 66 69 6c 65 73 29 2c 20 | 61 6e 64 20 5c 76 61 72 |files), |and \var|
|00000360| 7b 74 79 70 65 7d 20 69 | 73 20 74 68 65 20 66 69 |{type} i|s the fi|
|00000370| 6c 65 20 74 79 70 65 2c | 20 77 68 69 63 68 20 68 |le type,| which h|
|00000380| 61 73 20 6f 6e 65 20 6f | 66 20 74 68 65 20 76 61 |as one o|f the va|
|00000390| 6c 75 65 73 0a 5c 63 6f | 64 65 7b 50 59 5f 53 4f |lues.\co|de{PY_SO|
|000003a0| 55 52 43 45 7d 2c 20 5c | 63 6f 64 65 7b 50 59 5f |URCE}, \|code{PY_|
|000003b0| 43 4f 4d 50 49 4c 45 44 | 7d 20 6f 72 20 5c 63 6f |COMPILED|} or \co|
|000003c0| 64 65 7b 43 5f 45 58 54 | 45 4e 53 49 4f 4e 7d 2c |de{C_EXT|ENSION},|
|000003d0| 20 64 65 66 69 6e 65 64 | 0a 62 65 6c 6f 77 2e 20 | defined|.below. |
|000003e0| 20 28 53 79 73 74 65 6d | 2d 64 65 70 65 6e 64 65 | (System|-depende|
|000003f0| 6e 74 20 76 61 6c 75 65 | 73 20 6d 61 79 20 61 6c |nt value|s may al|
|00000400| 73 6f 20 62 65 20 72 65 | 74 75 72 6e 65 64 2e 29 |so be re|turned.)|
|00000410| 0a 5c 65 6e 64 7b 66 75 | 6e 63 64 65 73 63 7d 0a |.\end{fu|ncdesc}.|
|00000420| 0a 5c 62 65 67 69 6e 7b | 66 75 6e 63 64 65 73 63 |.\begin{|funcdesc|
|00000430| 7d 7b 66 69 6e 64 5f 6d | 6f 64 75 6c 65 7d 7b 6e |}{find_m|odule}{n|
|00000440| 61 6d 65 5c 2c 20 5c 6f | 70 74 69 6f 6e 61 6c 7b |ame\, \o|ptional{|
|00000450| 70 61 74 68 7d 7d 0a 54 | 72 79 20 74 6f 20 66 69 |path}}.T|ry to fi|
|00000460| 6e 64 20 74 68 65 20 6d | 6f 64 75 6c 65 20 5c 76 |nd the m|odule \v|
|00000470| 61 72 7b 6e 61 6d 65 7d | 20 6f 6e 20 74 68 65 20 |ar{name}| on the |
|00000480| 73 65 61 72 63 68 20 70 | 61 74 68 20 5c 76 61 72 |search p|ath \var|
|00000490| 7b 70 61 74 68 7d 2e 20 | 20 54 68 65 0a 64 65 66 |{path}. | The.def|
|000004a0| 61 75 6c 74 20 5c 76 61 | 72 7b 70 61 74 68 7d 20 |ault \va|r{path} |
|000004b0| 69 73 20 5c 63 6f 64 65 | 7b 73 79 73 2e 70 61 74 |is \code|{sys.pat|
|000004c0| 68 7d 2e 20 20 54 68 65 | 20 72 65 74 75 72 6e 20 |h}. The| return |
|000004d0| 76 61 6c 75 65 20 69 73 | 20 61 20 74 72 69 70 6c |value is| a tripl|
|000004e0| 65 0a 5c 63 6f 64 65 7b | 28 5c 76 61 72 7b 66 69 |e.\code{|(\var{fi|
|000004f0| 6c 65 7d 2c 20 5c 76 61 | 72 7b 70 61 74 68 6e 61 |le}, \va|r{pathna|
|00000500| 6d 65 7d 2c 20 5c 76 61 | 72 7b 64 65 73 63 72 69 |me}, \va|r{descri|
|00000510| 70 74 69 6f 6e 7d 29 7d | 20 77 68 65 72 65 0a 5c |ption})}| where.\|
|00000520| 76 61 72 7b 66 69 6c 65 | 7d 20 69 73 20 61 6e 20 |var{file|} is an |
|00000530| 6f 70 65 6e 20 66 69 6c | 65 20 6f 62 6a 65 63 74 |open fil|e object|
|00000540| 20 70 6f 73 69 74 69 6f | 6e 65 64 20 61 74 20 74 | positio|ned at t|
|00000550| 68 65 20 62 65 67 69 6e | 6e 69 6e 67 2c 0a 5c 76 |he begin|ning,.\v|
|00000560| 61 72 7b 70 61 74 68 6e | 61 6d 65 7d 20 69 73 20 |ar{pathn|ame} is |
|00000570| 74 68 65 20 70 61 74 68 | 6e 61 6d 65 20 6f 66 20 |the path|name of |
|00000580| 74 68 65 0a 66 69 6c 65 | 20 66 6f 75 6e 64 2c 20 |the.file| found, |
|00000590| 61 6e 64 20 5c 76 61 72 | 7b 64 65 73 63 72 69 70 |and \var|{descrip|
|000005a0| 74 69 6f 6e 7d 20 69 73 | 20 61 20 74 72 69 70 6c |tion} is| a tripl|
|000005b0| 65 20 61 73 20 63 6f 6e | 74 61 69 6e 65 64 20 69 |e as con|tained i|
|000005c0| 6e 20 74 68 65 20 6c 69 | 73 74 0a 72 65 74 75 72 |n the li|st.retur|
|000005d0| 6e 65 64 20 62 79 20 5c | 63 6f 64 65 7b 67 65 74 |ned by \|code{get|
|000005e0| 5f 73 75 66 66 69 78 65 | 73 7d 20 64 65 73 63 72 |_suffixe|s} descr|
|000005f0| 69 62 69 6e 67 20 74 68 | 65 20 6b 69 6e 64 20 6f |ibing th|e kind o|
|00000600| 66 20 66 69 6c 65 20 66 | 6f 75 6e 64 2e 0a 5c 65 |f file f|ound..\e|
|00000610| 6e 64 7b 66 75 6e 63 64 | 65 73 63 7d 0a 0a 5c 62 |nd{funcd|esc}..\b|
|00000620| 65 67 69 6e 7b 66 75 6e | 63 64 65 73 63 7d 7b 69 |egin{fun|cdesc}{i|
|00000630| 6e 69 74 5f 62 75 69 6c | 74 69 6e 7d 7b 6e 61 6d |nit_buil|tin}{nam|
|00000640| 65 7d 0a 49 6e 69 74 69 | 61 6c 69 7a 65 20 74 68 |e}.Initi|alize th|
|00000650| 65 20 62 75 69 6c 74 2d | 69 6e 20 6d 6f 64 75 6c |e built-|in modul|
|00000660| 65 20 63 61 6c 6c 65 64 | 20 5c 76 61 72 7b 6e 61 |e called| \var{na|
|00000670| 6d 65 7d 20 61 6e 64 20 | 72 65 74 75 72 6e 20 69 |me} and |return i|
|00000680| 74 73 20 6d 6f 64 75 6c | 65 0a 6f 62 6a 65 63 74 |ts modul|e.object|
|00000690| 2e 20 20 49 66 20 74 68 | 65 20 6d 6f 64 75 6c 65 |. If th|e module|
|000006a0| 20 77 61 73 20 61 6c 72 | 65 61 64 79 20 69 6e 69 | was alr|eady ini|
|000006b0| 74 69 61 6c 69 7a 65 64 | 2c 20 69 74 20 77 69 6c |tialized|, it wil|
|000006c0| 6c 20 62 65 20 69 6e 69 | 74 69 61 6c 69 7a 65 64 |l be ini|tialized|
|000006d0| 0a 7b 5c 65 6d 20 61 67 | 61 69 6e 7d 2e 20 20 41 |.{\em ag|ain}. A|
|000006e0| 20 66 65 77 20 6d 6f 64 | 75 6c 65 73 20 63 61 6e | few mod|ules can|
|000006f0| 6e 6f 74 20 62 65 20 69 | 6e 69 74 69 61 6c 69 7a |not be i|nitializ|
|00000700| 65 64 20 74 77 69 63 65 | 20 2d 2d 2d 20 61 74 74 |ed twice| --- att|
|00000710| 65 6d 70 74 69 6e 67 0a | 74 6f 20 69 6e 69 74 69 |empting.|to initi|
|00000720| 61 6c 69 7a 65 20 74 68 | 65 73 65 20 61 67 61 69 |alize th|ese agai|
|00000730| 6e 20 77 69 6c 6c 20 72 | 61 69 73 65 20 61 6e 20 |n will r|aise an |
|00000740| 5c 63 6f 64 65 7b 49 6d | 70 6f 72 74 45 72 72 6f |\code{Im|portErro|
|00000750| 72 7d 20 65 78 63 65 70 | 74 69 6f 6e 2e 0a 49 66 |r} excep|tion..If|
|00000760| 20 74 68 65 72 65 20 69 | 73 20 6e 6f 0a 62 75 69 | there i|s no.bui|
|00000770| 6c 74 2d 69 6e 20 6d 6f | 64 75 6c 65 20 63 61 6c |lt-in mo|dule cal|
|00000780| 6c 65 64 20 5c 76 61 72 | 7b 6e 61 6d 65 7d 2c 20 |led \var|{name}, |
|00000790| 5c 63 6f 64 65 7b 4e 6f | 6e 65 7d 20 69 73 20 72 |\code{No|ne} is r|
|000007a0| 65 74 75 72 6e 65 64 2e | 0a 5c 65 6e 64 7b 66 75 |eturned.|.\end{fu|
|000007b0| 6e 63 64 65 73 63 7d 0a | 0a 5c 62 65 67 69 6e 7b |ncdesc}.|.\begin{|
|000007c0| 66 75 6e 63 64 65 73 63 | 7d 7b 69 6e 69 74 5f 66 |funcdesc|}{init_f|
|000007d0| 72 6f 7a 65 6e 7d 7b 6e | 61 6d 65 7d 0a 49 6e 69 |rozen}{n|ame}.Ini|
|000007e0| 74 69 61 6c 69 7a 65 20 | 74 68 65 20 66 72 6f 7a |tialize |the froz|
|000007f0| 65 6e 20 6d 6f 64 75 6c | 65 20 63 61 6c 6c 65 64 |en modul|e called|
|00000800| 20 5c 76 61 72 7b 6e 61 | 6d 65 7d 20 61 6e 64 20 | \var{na|me} and |
|00000810| 72 65 74 75 72 6e 20 69 | 74 73 20 6d 6f 64 75 6c |return i|ts modul|
|00000820| 65 0a 6f 62 6a 65 63 74 | 2e 20 20 49 66 20 74 68 |e.object|. If th|
|00000830| 65 20 6d 6f 64 75 6c 65 | 20 77 61 73 20 61 6c 72 |e module| was alr|
|00000840| 65 61 64 79 20 69 6e 69 | 74 69 61 6c 69 7a 65 64 |eady ini|tialized|
|00000850| 2c 20 69 74 20 77 69 6c | 6c 20 62 65 20 69 6e 69 |, it wil|l be ini|
|00000860| 74 69 61 6c 69 7a 65 64 | 0a 7b 5c 65 6d 20 61 67 |tialized|.{\em ag|
|00000870| 61 69 6e 7d 2e 20 20 49 | 66 20 74 68 65 72 65 20 |ain}. I|f there |
|00000880| 69 73 20 6e 6f 20 66 72 | 6f 7a 65 6e 20 6d 6f 64 |is no fr|ozen mod|
|00000890| 75 6c 65 20 63 61 6c 6c | 65 64 20 5c 76 61 72 7b |ule call|ed \var{|
|000008a0| 6e 61 6d 65 7d 2c 0a 5c | 63 6f 64 65 7b 4e 6f 6e |name},.\|code{Non|
|000008b0| 65 7d 20 69 73 20 72 65 | 74 75 72 6e 65 64 2e 20 |e} is re|turned. |
|000008c0| 20 28 46 72 6f 7a 65 6e | 20 6d 6f 64 75 6c 65 73 | (Frozen| modules|
|000008d0| 20 61 72 65 20 6d 6f 64 | 75 6c 65 73 20 77 72 69 | are mod|ules wri|
|000008e0| 74 74 65 6e 20 69 6e 0a | 50 79 74 68 6f 6e 20 77 |tten in.|Python w|
|000008f0| 68 6f 73 65 20 63 6f 6d | 70 69 6c 65 64 20 62 79 |hose com|piled by|
|00000900| 74 65 2d 63 6f 64 65 20 | 6f 62 6a 65 63 74 20 69 |te-code |object i|
|00000910| 73 20 69 6e 63 6f 72 70 | 6f 72 61 74 65 64 20 69 |s incorp|orated i|
|00000920| 6e 74 6f 20 61 0a 63 75 | 73 74 6f 6d 2d 62 75 69 |nto a.cu|stom-bui|
|00000930| 6c 74 20 50 79 74 68 6f | 6e 20 69 6e 74 65 72 70 |lt Pytho|n interp|
|00000940| 72 65 74 65 72 20 62 79 | 20 50 79 74 68 6f 6e 27 |reter by| Python'|
|00000950| 73 20 5c 63 6f 64 65 7b | 66 72 65 65 7a 65 7d 20 |s \code{|freeze} |
|00000960| 75 74 69 6c 69 74 79 2e | 0a 53 65 65 20 5c 63 6f |utility.|.See \co|
|00000970| 64 65 7b 54 6f 6f 6c 73 | 2f 66 72 65 65 7a 65 7d |de{Tools|/freeze}|
|00000980| 20 66 6f 72 20 6e 6f 77 | 2e 29 0a 5c 65 6e 64 7b | for now|.).\end{|
|00000990| 66 75 6e 63 64 65 73 63 | 7d 0a 0a 5c 62 65 67 69 |funcdesc|}..\begi|
|000009a0| 6e 7b 66 75 6e 63 64 65 | 73 63 7d 7b 69 73 5f 62 |n{funcde|sc}{is_b|
|000009b0| 75 69 6c 74 69 6e 7d 7b | 6e 61 6d 65 7d 0a 52 65 |uiltin}{|name}.Re|
|000009c0| 74 75 72 6e 20 5c 63 6f | 64 65 7b 31 7d 20 69 66 |turn \co|de{1} if|
|000009d0| 20 74 68 65 72 65 20 69 | 73 20 61 20 62 75 69 6c | there i|s a buil|
|000009e0| 74 2d 69 6e 20 6d 6f 64 | 75 6c 65 20 63 61 6c 6c |t-in mod|ule call|
|000009f0| 65 64 20 5c 76 61 72 7b | 6e 61 6d 65 7d 20 77 68 |ed \var{|name} wh|
|00000a00| 69 63 68 20 63 61 6e 20 | 62 65 0a 69 6e 69 74 69 |ich can |be.initi|
|00000a10| 61 6c 69 7a 65 64 20 61 | 67 61 69 6e 2e 20 20 52 |alized a|gain. R|
|00000a20| 65 74 75 72 6e 20 5c 63 | 6f 64 65 7b 2d 31 7d 20 |eturn \c|ode{-1} |
|00000a30| 69 66 20 74 68 65 72 65 | 20 69 73 20 61 20 62 75 |if there| is a bu|
|00000a40| 69 6c 74 2d 69 6e 20 6d | 6f 64 75 6c 65 0a 63 61 |ilt-in m|odule.ca|
|00000a50| 6c 6c 65 64 20 5c 76 61 | 72 7b 6e 61 6d 65 7d 20 |lled \va|r{name} |
|00000a60| 77 68 69 63 68 20 63 61 | 6e 6e 6f 74 20 62 65 20 |which ca|nnot be |
|00000a70| 69 6e 69 74 69 61 6c 69 | 7a 65 64 20 61 67 61 69 |initiali|zed agai|
|00000a80| 6e 20 28 73 65 65 0a 5c | 63 6f 64 65 7b 69 6e 69 |n (see.\|code{ini|
|00000a90| 74 5f 62 75 69 6c 74 69 | 6e 7d 29 2e 20 20 52 65 |t_builti|n}). Re|
|00000aa0| 74 75 72 6e 20 5c 63 6f | 64 65 7b 30 7d 20 69 66 |turn \co|de{0} if|
|00000ab0| 20 74 68 65 72 65 20 69 | 73 20 6e 6f 20 62 75 69 | there i|s no bui|
|00000ac0| 6c 74 2d 69 6e 20 6d 6f | 64 75 6c 65 0a 63 61 6c |lt-in mo|dule.cal|
|00000ad0| 6c 65 64 20 5c 76 61 72 | 7b 6e 61 6d 65 7d 2e 0a |led \var|{name}..|
|00000ae0| 5c 65 6e 64 7b 66 75 6e | 63 64 65 73 63 7d 0a 0a |\end{fun|cdesc}..|
|00000af0| 5c 62 65 67 69 6e 7b 66 | 75 6e 63 64 65 73 63 7d |\begin{f|uncdesc}|
|00000b00| 7b 69 73 5f 66 72 6f 7a | 65 6e 7d 7b 6e 61 6d 65 |{is_froz|en}{name|
|00000b10| 7d 0a 52 65 74 75 72 6e | 20 5c 63 6f 64 65 7b 31 |}.Return| \code{1|
|00000b20| 7d 20 69 66 20 74 68 65 | 72 65 20 69 73 20 61 20 |} if the|re is a |
|00000b30| 66 72 6f 7a 65 6e 20 6d | 6f 64 75 6c 65 20 28 73 |frozen m|odule (s|
|00000b40| 65 65 20 5c 63 6f 64 65 | 7b 69 6e 69 74 5f 66 72 |ee \code|{init_fr|
|00000b50| 6f 7a 65 6e 7d 29 0a 63 | 61 6c 6c 65 64 20 5c 76 |ozen}).c|alled \v|
|00000b60| 61 72 7b 6e 61 6d 65 7d | 2c 20 5c 63 6f 64 65 7b |ar{name}|, \code{|
|00000b70| 30 7d 20 69 66 20 74 68 | 65 72 65 20 69 73 20 6e |0} if th|ere is n|
|00000b80| 6f 20 73 75 63 68 20 6d | 6f 64 75 6c 65 2e 0a 5c |o such m|odule..\|
|00000b90| 65 6e 64 7b 66 75 6e 63 | 64 65 73 63 7d 0a 0a 5c |end{func|desc}..\|
|00000ba0| 62 65 67 69 6e 7b 66 75 | 6e 63 64 65 73 63 7d 7b |begin{fu|ncdesc}{|
|00000bb0| 6c 6f 61 64 5f 63 6f 6d | 70 69 6c 65 64 7d 7b 6e |load_com|piled}{n|
|00000bc0| 61 6d 65 5c 2c 20 70 61 | 74 68 6e 61 6d 65 5c 2c |ame\, pa|thname\,|
|00000bd0| 20 66 69 6c 65 7d 0a 4c | 6f 61 64 20 61 6e 64 20 | file}.L|oad and |
|00000be0| 69 6e 69 74 69 61 6c 69 | 7a 65 20 61 20 6d 6f 64 |initiali|ze a mod|
|00000bf0| 75 6c 65 20 69 6d 70 6c | 65 6d 65 6e 74 65 64 20 |ule impl|emented |
|00000c00| 61 73 20 61 20 62 79 74 | 65 2d 63 6f 6d 70 69 6c |as a byt|e-compil|
|00000c10| 65 64 20 63 6f 64 65 20 | 66 69 6c 65 0a 61 6e 64 |ed code |file.and|
|00000c20| 20 72 65 74 75 72 6e 20 | 69 74 73 20 6d 6f 64 75 | return |its modu|
|00000c30| 6c 65 20 6f 62 6a 65 63 | 74 2e 20 20 49 66 20 74 |le objec|t. If t|
|00000c40| 68 65 20 6d 6f 64 75 6c | 65 20 77 61 73 20 61 6c |he modul|e was al|
|00000c50| 72 65 61 64 79 20 69 6e | 69 74 69 61 6c 69 7a 65 |ready in|itialize|
|00000c60| 64 2c 0a 69 74 20 77 69 | 6c 6c 20 62 65 20 69 6e |d,.it wi|ll be in|
|00000c70| 69 74 69 61 6c 69 7a 65 | 64 20 7b 5c 65 6d 20 61 |itialize|d {\em a|
|00000c80| 67 61 69 6e 7d 2e 20 20 | 54 68 65 20 5c 76 61 72 |gain}. |The \var|
|00000c90| 7b 6e 61 6d 65 7d 20 61 | 72 67 75 6d 65 6e 74 20 |{name} a|rgument |
|00000ca0| 69 73 20 75 73 65 64 0a | 74 6f 20 63 72 65 61 74 |is used.|to creat|
|00000cb0| 65 20 6f 72 20 61 63 63 | 65 73 73 20 61 20 6d 6f |e or acc|ess a mo|
|00000cc0| 64 75 6c 65 20 6f 62 6a | 65 63 74 2e 20 20 54 68 |dule obj|ect. Th|
|00000cd0| 65 20 5c 76 61 72 7b 70 | 61 74 68 6e 61 6d 65 7d |e \var{p|athname}|
|00000ce0| 20 61 72 67 75 6d 65 6e | 74 0a 70 6f 69 6e 74 73 | argumen|t.points|
|00000cf0| 20 74 6f 20 74 68 65 20 | 62 79 74 65 2d 63 6f 6d | to the |byte-com|
|00000d00| 70 69 6c 65 64 20 63 6f | 64 65 20 66 69 6c 65 2e |piled co|de file.|
|00000d10| 20 20 54 68 65 20 5c 76 | 61 72 7b 66 69 6c 65 7d | The \v|ar{file}|
|00000d20| 0a 61 72 67 75 6d 65 6e | 74 20 69 73 20 74 68 65 |.argumen|t is the|
|00000d30| 20 62 79 74 65 2d 63 6f | 6d 70 69 6c 65 64 20 63 | byte-co|mpiled c|
|00000d40| 6f 64 65 20 66 69 6c 65 | 2c 20 6f 70 65 6e 20 66 |ode file|, open f|
|00000d50| 6f 72 20 72 65 61 64 69 | 6e 67 20 69 6e 20 62 69 |or readi|ng in bi|
|00000d60| 6e 61 72 79 0a 6d 6f 64 | 65 2c 20 66 72 6f 6d 20 |nary.mod|e, from |
|00000d70| 74 68 65 20 62 65 67 69 | 6e 6e 69 6e 67 2e 0a 49 |the begi|nning..I|
|00000d80| 74 20 6d 75 73 74 20 63 | 75 72 72 65 6e 74 6c 79 |t must c|urrently|
|00000d90| 20 62 65 20 61 20 72 65 | 61 6c 20 66 69 6c 65 20 | be a re|al file |
|00000da0| 6f 62 6a 65 63 74 2c 20 | 6e 6f 74 20 61 0a 75 73 |object, |not a.us|
|00000db0| 65 72 2d 64 65 66 69 6e | 65 64 20 63 6c 61 73 73 |er-defin|ed class|
|00000dc0| 20 65 6d 75 6c 61 74 69 | 6e 67 20 61 20 66 69 6c | emulati|ng a fil|
|00000dd0| 65 2e 0a 5c 65 6e 64 7b | 66 75 6e 63 64 65 73 63 |e..\end{|funcdesc|
|00000de0| 7d 0a 0a 5c 62 65 67 69 | 6e 7b 66 75 6e 63 64 65 |}..\begi|n{funcde|
|00000df0| 73 63 7d 7b 6c 6f 61 64 | 5f 64 79 6e 61 6d 69 63 |sc}{load|_dynamic|
|00000e00| 7d 7b 6e 61 6d 65 5c 2c | 20 70 61 74 68 6e 61 6d |}{name\,| pathnam|
|00000e10| 65 5c 2c 20 5c 6f 70 74 | 69 6f 6e 61 6c 7b 66 69 |e\, \opt|ional{fi|
|00000e20| 6c 65 7d 7d 0a 4c 6f 61 | 64 20 61 6e 64 20 69 6e |le}}.Loa|d and in|
|00000e30| 69 74 69 61 6c 69 7a 65 | 20 61 20 6d 6f 64 75 6c |itialize| a modul|
|00000e40| 65 20 69 6d 70 6c 65 6d | 65 6e 74 65 64 20 61 73 |e implem|ented as|
|00000e50| 20 61 20 64 79 6e 61 6d | 69 63 61 6c 6c 79 20 6c | a dynam|ically l|
|00000e60| 6f 61 64 61 62 6c 65 0a | 73 68 61 72 65 64 20 6c |oadable.|shared l|
|00000e70| 69 62 72 61 72 79 20 61 | 6e 64 20 72 65 74 75 72 |ibrary a|nd retur|
|00000e80| 6e 20 69 74 73 20 6d 6f | 64 75 6c 65 20 6f 62 6a |n its mo|dule obj|
|00000e90| 65 63 74 2e 20 20 49 66 | 20 74 68 65 20 6d 6f 64 |ect. If| the mod|
|00000ea0| 75 6c 65 20 77 61 73 0a | 61 6c 72 65 61 64 79 20 |ule was.|already |
|00000eb0| 69 6e 69 74 69 61 6c 69 | 7a 65 64 2c 20 69 74 20 |initiali|zed, it |
|00000ec0| 77 69 6c 6c 20 62 65 20 | 69 6e 69 74 69 61 6c 69 |will be |initiali|
|00000ed0| 7a 65 64 20 7b 5c 65 6d | 20 61 67 61 69 6e 7d 2e |zed {\em| again}.|
|00000ee0| 20 20 53 6f 6d 65 20 6d | 6f 64 75 6c 65 73 0a 64 | Some m|odules.d|
|00000ef0| 6f 6e 27 74 20 6c 69 6b | 65 20 74 68 61 74 20 61 |on't lik|e that a|
|00000f00| 6e 64 20 6d 61 79 20 72 | 61 69 73 65 20 61 6e 20 |nd may r|aise an |
|00000f10| 65 78 63 65 70 74 69 6f | 6e 2e 20 20 54 68 65 20 |exceptio|n. The |
|00000f20| 5c 76 61 72 7b 70 61 74 | 68 6e 61 6d 65 7d 0a 61 |\var{pat|hname}.a|
|00000f30| 72 67 75 6d 65 6e 74 20 | 6d 75 73 74 20 70 6f 69 |rgument |must poi|
|00000f40| 6e 74 20 74 6f 20 74 68 | 65 20 73 68 61 72 65 64 |nt to th|e shared|
|00000f50| 20 6c 69 62 72 61 72 79 | 2e 20 20 54 68 65 20 5c | library|. The \|
|00000f60| 76 61 72 7b 6e 61 6d 65 | 7d 20 61 72 67 75 6d 65 |var{name|} argume|
|00000f70| 6e 74 20 69 73 0a 75 73 | 65 64 20 74 6f 20 63 6f |nt is.us|ed to co|
|00000f80| 6e 73 74 72 75 63 74 20 | 74 68 65 20 6e 61 6d 65 |nstruct |the name|
|00000f90| 20 6f 66 20 74 68 65 20 | 69 6e 69 74 69 61 6c 69 | of the |initiali|
|00000fa0| 7a 61 74 69 6f 6e 20 66 | 75 6e 63 74 69 6f 6e 3a |zation f|unction:|
|00000fb0| 20 61 6e 20 65 78 74 65 | 72 6e 61 6c 0a 43 20 66 | an exte|rnal.C f|
|00000fc0| 75 6e 63 74 69 6f 6e 20 | 63 61 6c 6c 65 64 20 5c |unction |called \|
|00000fd0| 63 6f 64 65 7b 69 6e 69 | 74 5c 76 61 72 7b 6e 61 |code{ini|t\var{na|
|00000fe0| 6d 65 7d 28 29 7d 20 69 | 6e 20 74 68 65 20 73 68 |me}()} i|n the sh|
|00000ff0| 61 72 65 64 20 6c 69 62 | 72 61 72 79 20 69 73 0a |ared lib|rary is.|
|00001000| 63 61 6c 6c 65 64 2e 20 | 20 54 68 65 20 6f 70 74 |called. | The opt|
|00001010| 69 6f 6e 61 6c 20 5c 76 | 61 72 7b 66 69 6c 65 7d |ional \v|ar{file}|
|00001020| 20 61 72 67 6d 65 6e 74 | 20 69 73 20 69 67 6e 6f | argment| is igno|
|00001030| 72 65 64 2e 20 20 28 4e | 6f 74 65 3a 20 75 73 69 |red. (N|ote: usi|
|00001040| 6e 67 0a 73 68 61 72 65 | 64 20 6c 69 62 72 61 72 |ng.share|d librar|
|00001050| 69 65 73 20 69 73 20 68 | 69 67 68 6c 79 20 73 79 |ies is h|ighly sy|
|00001060| 73 74 65 6d 20 64 65 70 | 65 6e 64 65 6e 74 2c 20 |stem dep|endent, |
|00001070| 61 6e 64 20 6e 6f 74 20 | 61 6c 6c 20 73 79 73 74 |and not |all syst|
|00001080| 65 6d 73 0a 73 75 70 70 | 6f 72 74 20 69 74 2e 29 |ems.supp|ort it.)|
|00001090| 0a 5c 65 6e 64 7b 66 75 | 6e 63 64 65 73 63 7d 0a |.\end{fu|ncdesc}.|
|000010a0| 0a 5c 62 65 67 69 6e 7b | 66 75 6e 63 64 65 73 63 |.\begin{|funcdesc|
|000010b0| 7d 7b 6c 6f 61 64 5f 73 | 6f 75 72 63 65 7d 7b 6e |}{load_s|ource}{n|
|000010c0| 61 6d 65 5c 2c 20 70 61 | 74 68 6e 61 6d 65 5c 2c |ame\, pa|thname\,|
|000010d0| 20 66 69 6c 65 7d 0a 4c | 6f 61 64 20 61 6e 64 20 | file}.L|oad and |
|000010e0| 69 6e 69 74 69 61 6c 69 | 7a 65 20 61 20 6d 6f 64 |initiali|ze a mod|
|000010f0| 75 6c 65 20 69 6d 70 6c | 65 6d 65 6e 74 65 64 20 |ule impl|emented |
|00001100| 61 73 20 61 20 50 79 74 | 68 6f 6e 20 73 6f 75 72 |as a Pyt|hon sour|
|00001110| 63 65 20 66 69 6c 65 20 | 61 6e 64 0a 72 65 74 75 |ce file |and.retu|
|00001120| 72 6e 20 69 74 73 20 6d | 6f 64 75 6c 65 20 6f 62 |rn its m|odule ob|
|00001130| 6a 65 63 74 2e 20 20 49 | 66 20 74 68 65 20 6d 6f |ject. I|f the mo|
|00001140| 64 75 6c 65 20 77 61 73 | 20 61 6c 72 65 61 64 79 |dule was| already|
|00001150| 20 69 6e 69 74 69 61 6c | 69 7a 65 64 2c 20 69 74 | initial|ized, it|
|00001160| 0a 77 69 6c 6c 20 62 65 | 20 69 6e 69 74 69 61 6c |.will be| initial|
|00001170| 69 7a 65 64 20 7b 5c 65 | 6d 20 61 67 61 69 6e 7d |ized {\e|m again}|
|00001180| 2e 20 20 54 68 65 20 5c | 76 61 72 7b 6e 61 6d 65 |. The \|var{name|
|00001190| 7d 20 61 72 67 75 6d 65 | 6e 74 20 69 73 20 75 73 |} argume|nt is us|
|000011a0| 65 64 20 74 6f 0a 63 72 | 65 61 74 65 20 6f 72 20 |ed to.cr|eate or |
|000011b0| 61 63 63 65 73 73 20 61 | 20 6d 6f 64 75 6c 65 20 |access a| module |
|000011c0| 6f 62 6a 65 63 74 2e 20 | 20 54 68 65 20 5c 76 61 |object. | The \va|
|000011d0| 72 7b 70 61 74 68 6e 61 | 6d 65 7d 20 61 72 67 75 |r{pathna|me} argu|
|000011e0| 6d 65 6e 74 20 70 6f 69 | 6e 74 73 0a 74 6f 20 74 |ment poi|nts.to t|
|000011f0| 68 65 20 73 6f 75 72 63 | 65 20 66 69 6c 65 2e 20 |he sourc|e file. |
|00001200| 20 54 68 65 20 5c 76 61 | 72 7b 66 69 6c 65 7d 20 | The \va|r{file} |
|00001210| 61 72 67 75 6d 65 6e 74 | 20 69 73 20 74 68 65 20 |argument| is the |
|00001220| 73 6f 75 72 63 65 0a 66 | 69 6c 65 2c 20 6f 70 65 |source.f|ile, ope|
|00001230| 6e 20 66 6f 72 20 72 65 | 61 64 69 6e 67 20 61 73 |n for re|ading as|
|00001240| 20 74 65 78 74 2c 20 66 | 72 6f 6d 20 74 68 65 20 | text, f|rom the |
|00001250| 62 65 67 69 6e 6e 69 6e | 67 2e 0a 49 74 20 6d 75 |beginnin|g..It mu|
|00001260| 73 74 20 63 75 72 72 65 | 6e 74 6c 79 20 62 65 20 |st curre|ntly be |
|00001270| 61 20 72 65 61 6c 20 66 | 69 6c 65 0a 6f 62 6a 65 |a real f|ile.obje|
|00001280| 63 74 2c 20 6e 6f 74 20 | 61 20 75 73 65 72 2d 64 |ct, not |a user-d|
|00001290| 65 66 69 6e 65 64 20 63 | 6c 61 73 73 20 65 6d 75 |efined c|lass emu|
|000012a0| 6c 61 74 69 6e 67 20 61 | 20 66 69 6c 65 2e 20 20 |lating a| file. |
|000012b0| 4e 6f 74 65 20 74 68 61 | 74 20 69 66 20 61 0a 70 |Note tha|t if a.p|
|000012c0| 72 6f 70 65 72 6c 79 20 | 6d 61 74 63 68 69 6e 67 |roperly |matching|
|000012d0| 20 62 79 74 65 2d 63 6f | 6d 70 69 6c 65 64 20 66 | byte-co|mpiled f|
|000012e0| 69 6c 65 20 28 77 69 74 | 68 20 73 75 66 66 69 78 |ile (wit|h suffix|
|000012f0| 20 5c 63 6f 64 65 7b 2e | 70 79 63 7d 29 20 65 78 | \code{.|pyc}) ex|
|00001300| 69 73 74 73 2c 0a 69 74 | 20 77 69 6c 6c 20 62 65 |ists,.it| will be|
|00001310| 20 75 73 65 64 20 69 6e | 73 74 65 61 64 20 6f 66 | used in|stead of|
|00001320| 20 70 61 72 73 69 6e 67 | 20 74 68 65 20 67 69 76 | parsing| the giv|
|00001330| 65 6e 20 73 6f 75 72 63 | 65 20 66 69 6c 65 2e 0a |en sourc|e file..|
|00001340| 5c 65 6e 64 7b 66 75 6e | 63 64 65 73 63 7d 0a 0a |\end{fun|cdesc}..|
|00001350| 5c 62 65 67 69 6e 7b 66 | 75 6e 63 64 65 73 63 7d |\begin{f|uncdesc}|
|00001360| 7b 6e 65 77 5f 6d 6f 64 | 75 6c 65 7d 7b 6e 61 6d |{new_mod|ule}{nam|
|00001370| 65 7d 0a 52 65 74 75 72 | 6e 20 61 20 6e 65 77 20 |e}.Retur|n a new |
|00001380| 65 6d 70 74 79 20 6d 6f | 64 75 6c 65 20 6f 62 6a |empty mo|dule obj|
|00001390| 65 63 74 20 63 61 6c 6c | 65 64 20 5c 76 61 72 7b |ect call|ed \var{|
|000013a0| 6e 61 6d 65 7d 2e 20 20 | 54 68 69 73 20 6f 62 6a |name}. |This obj|
|000013b0| 65 63 74 20 69 73 0a 7b | 5c 65 6d 20 6e 6f 74 7d |ect is.{|\em not}|
|000013c0| 20 69 6e 73 65 72 74 65 | 64 20 69 6e 20 5c 63 6f | inserte|d in \co|
|000013d0| 64 65 7b 73 79 73 2e 6d | 6f 64 75 6c 65 73 7d 2e |de{sys.m|odules}.|
|000013e0| 0a 5c 65 6e 64 7b 66 75 | 6e 63 64 65 73 63 7d 0a |.\end{fu|ncdesc}.|
|000013f0| 0a 54 68 65 20 66 6f 6c | 6c 6f 77 69 6e 67 20 63 |.The fol|lowing c|
|00001400| 6f 6e 73 74 61 6e 74 73 | 20 77 69 74 68 20 69 6e |onstants| with in|
|00001410| 74 65 67 65 72 20 76 61 | 6c 75 65 73 2c 20 64 65 |teger va|lues, de|
|00001420| 66 69 6e 65 64 20 69 6e | 20 74 68 65 20 6d 6f 64 |fined in| the mod|
|00001430| 75 6c 65 2c 0a 61 72 65 | 20 75 73 65 64 20 74 6f |ule,.are| used to|
|00001440| 20 69 6e 64 69 63 61 74 | 65 20 74 68 65 20 73 65 | indicat|e the se|
|00001450| 61 72 63 68 20 72 65 73 | 75 6c 74 20 6f 66 20 5c |arch res|ult of \|
|00001460| 63 6f 64 65 7b 69 6d 70 | 2e 66 69 6e 64 5f 6d 6f |code{imp|.find_mo|
|00001470| 64 75 6c 65 7d 2e 0a 0a | 5c 62 65 67 69 6e 7b 64 |dule}...|\begin{d|
|00001480| 61 74 61 64 65 73 63 7d | 7b 53 45 41 52 43 48 5f |atadesc}|{SEARCH_|
|00001490| 45 52 52 4f 52 7d 0a 54 | 68 65 20 6d 6f 64 75 6c |ERROR}.T|he modul|
|000014a0| 65 20 77 61 73 20 6e 6f | 74 20 66 6f 75 6e 64 2e |e was no|t found.|
|000014b0| 0a 5c 65 6e 64 7b 64 61 | 74 61 64 65 73 63 7d 0a |.\end{da|tadesc}.|
|000014c0| 0a 5c 62 65 67 69 6e 7b | 64 61 74 61 64 65 73 63 |.\begin{|datadesc|
|000014d0| 7d 7b 50 59 5f 53 4f 55 | 52 43 45 7d 0a 54 68 65 |}{PY_SOU|RCE}.The|
|000014e0| 20 6d 6f 64 75 6c 65 20 | 77 61 73 20 66 6f 75 6e | module |was foun|
|000014f0| 64 20 61 73 20 61 20 73 | 6f 75 72 63 65 20 66 69 |d as a s|ource fi|
|00001500| 6c 65 2e 0a 5c 65 6e 64 | 7b 64 61 74 61 64 65 73 |le..\end|{datades|
|00001510| 63 7d 0a 0a 5c 62 65 67 | 69 6e 7b 64 61 74 61 64 |c}..\beg|in{datad|
|00001520| 65 73 63 7d 7b 50 59 5f | 43 4f 4d 50 49 4c 45 44 |esc}{PY_|COMPILED|
|00001530| 7d 0a 54 68 65 20 6d 6f | 64 75 6c 65 20 77 61 73 |}.The mo|dule was|
|00001540| 20 66 6f 75 6e 64 20 61 | 73 20 61 20 63 6f 6d 70 | found a|s a comp|
|00001550| 69 6c 65 64 20 63 6f 64 | 65 20 6f 62 6a 65 63 74 |iled cod|e object|
|00001560| 20 66 69 6c 65 2e 0a 5c | 65 6e 64 7b 64 61 74 61 | file..\|end{data|
|00001570| 64 65 73 63 7d 0a 0a 5c | 62 65 67 69 6e 7b 64 61 |desc}..\|begin{da|
|00001580| 74 61 64 65 73 63 7d 7b | 43 5f 45 58 54 45 4e 53 |tadesc}{|C_EXTENS|
|00001590| 49 4f 4e 7d 0a 54 68 65 | 20 6d 6f 64 75 6c 65 20 |ION}.The| module |
|000015a0| 77 61 73 20 66 6f 75 6e | 64 20 61 73 20 64 79 6e |was foun|d as dyn|
|000015b0| 61 6d 69 63 61 6c 6c 79 | 20 6c 6f 61 64 61 62 6c |amically| loadabl|
|000015c0| 65 20 73 68 61 72 65 64 | 20 6c 69 62 72 61 72 79 |e shared| library|
|000015d0| 2e 0a 5c 65 6e 64 7b 64 | 61 74 61 64 65 73 63 7d |..\end{d|atadesc}|
|000015e0| 0a 0a 5c 73 75 62 73 65 | 63 74 69 6f 6e 7b 45 78 |..\subse|ction{Ex|
|000015f0| 61 6d 70 6c 65 73 7d 0a | 54 68 65 20 66 6f 6c 6c |amples}.|The foll|
|00001600| 6f 77 69 6e 67 20 66 75 | 6e 63 74 69 6f 6e 20 65 |owing fu|nction e|
|00001610| 6d 75 6c 61 74 65 73 20 | 74 68 65 20 64 65 66 61 |mulates |the defa|
|00001620| 75 6c 74 20 69 6d 70 6f | 72 74 20 73 74 61 74 65 |ult impo|rt state|
|00001630| 6d 65 6e 74 3a 0a 0a 5c | 62 65 67 69 6e 7b 76 65 |ment:..\|begin{ve|
|00001640| 72 62 61 74 69 6d 7d 0a | 69 6d 70 6f 72 74 20 69 |rbatim}.|import i|
|00001650| 6d 70 0a 69 6d 70 6f 72 | 74 20 73 79 73 0a 0a 64 |mp.impor|t sys..d|
|00001660| 65 66 20 5f 5f 69 6d 70 | 6f 72 74 5f 5f 28 6e 61 |ef __imp|ort__(na|
|00001670| 6d 65 2c 20 67 6c 6f 62 | 61 6c 73 3d 4e 6f 6e 65 |me, glob|als=None|
|00001680| 2c 20 6c 6f 63 61 6c 73 | 3d 4e 6f 6e 65 2c 20 66 |, locals|=None, f|
|00001690| 72 6f 6d 6c 69 73 74 3d | 4e 6f 6e 65 29 3a 0a 20 |romlist=|None):. |
|000016a0| 20 20 20 23 20 46 61 73 | 74 20 70 61 74 68 3a 20 | # Fas|t path: |
|000016b0| 73 65 65 20 69 66 20 74 | 68 65 20 6d 6f 64 75 6c |see if t|he modul|
|000016c0| 65 20 68 61 73 20 61 6c | 72 65 61 64 79 20 62 65 |e has al|ready be|
|000016d0| 65 6e 20 69 6d 70 6f 72 | 74 65 64 2e 0a 20 20 20 |en impor|ted.. |
|000016e0| 20 69 66 20 73 79 73 2e | 6d 6f 64 75 6c 65 73 2e | if sys.|modules.|
|000016f0| 68 61 73 5f 6b 65 79 28 | 6e 61 6d 65 29 3a 0a 20 |has_key(|name):. |
|00001700| 20 20 20 20 20 20 20 72 | 65 74 75 72 6e 20 73 79 | r|eturn sy|
|00001710| 73 2e 6d 6f 64 75 6c 65 | 73 5b 6e 61 6d 65 5d 0a |s.module|s[name].|
|00001720| 0a 20 20 20 20 23 20 49 | 66 20 61 6e 79 20 6f 66 |. # I|f any of|
|00001730| 20 74 68 65 20 66 6f 6c | 6c 6f 77 69 6e 67 20 63 | the fol|lowing c|
|00001740| 61 6c 6c 73 20 72 61 69 | 73 65 73 20 61 6e 20 65 |alls rai|ses an e|
|00001750| 78 63 65 70 74 69 6f 6e | 2c 0a 20 20 20 20 23 20 |xception|,. # |
|00001760| 74 68 65 72 65 27 73 20 | 61 20 70 72 6f 62 6c 65 |there's |a proble|
|00001770| 6d 20 77 65 20 63 61 6e | 27 74 20 68 61 6e 64 6c |m we can|'t handl|
|00001780| 65 20 2d 2d 20 6c 65 74 | 20 74 68 65 20 63 61 6c |e -- let| the cal|
|00001790| 6c 65 72 20 68 61 6e 64 | 6c 65 20 69 74 2e 0a 0a |ler hand|le it...|
|000017a0| 20 20 20 20 23 20 53 65 | 65 20 69 66 20 69 74 27 | # Se|e if it'|
|000017b0| 73 20 61 20 62 75 69 6c | 74 2d 69 6e 20 6d 6f 64 |s a buil|t-in mod|
|000017c0| 75 6c 65 2e 0a 20 20 20 | 20 6d 20 3d 20 69 6d 70 |ule.. | m = imp|
|000017d0| 2e 69 6e 69 74 5f 62 75 | 69 6c 74 69 6e 28 6e 61 |.init_bu|iltin(na|
|000017e0| 6d 65 29 0a 20 20 20 20 | 69 66 20 6d 3a 0a 20 20 |me). |if m:. |
|000017f0| 20 20 20 20 20 20 72 65 | 74 75 72 6e 20 6d 0a 0a | re|turn m..|
|00001800| 20 20 20 20 23 20 53 65 | 65 20 69 66 20 69 74 27 | # Se|e if it'|
|00001810| 73 20 61 20 66 72 6f 7a | 65 6e 20 6d 6f 64 75 6c |s a froz|en modul|
|00001820| 65 2e 0a 20 20 20 20 6d | 20 3d 20 69 6d 70 2e 69 |e.. m| = imp.i|
|00001830| 6e 69 74 5f 66 72 6f 7a | 65 6e 28 6e 61 6d 65 29 |nit_froz|en(name)|
|00001840| 0a 20 20 20 20 69 66 20 | 6d 3a 0a 20 20 20 20 20 |. if |m:. |
|00001850| 20 20 20 72 65 74 75 72 | 6e 20 6d 0a 0a 20 20 20 | retur|n m.. |
|00001860| 20 23 20 53 65 61 72 63 | 68 20 74 68 65 20 64 65 | # Searc|h the de|
|00001870| 66 61 75 6c 74 20 70 61 | 74 68 20 28 69 2e 65 2e |fault pa|th (i.e.|
|00001880| 20 73 79 73 2e 70 61 74 | 68 29 2e 0a 20 20 20 20 | sys.pat|h).. |
|00001890| 66 70 2c 20 70 61 74 68 | 6e 61 6d 65 2c 20 28 73 |fp, path|name, (s|
|000018a0| 75 66 66 69 78 2c 20 6d | 6f 64 65 2c 20 74 79 70 |uffix, m|ode, typ|
|000018b0| 65 29 20 3d 20 69 6d 70 | 2e 66 69 6e 64 5f 6d 6f |e) = imp|.find_mo|
|000018c0| 64 75 6c 65 28 6e 61 6d | 65 29 0a 0a 20 20 20 20 |dule(nam|e).. |
|000018d0| 23 20 53 65 65 20 77 68 | 61 74 20 77 65 20 67 6f |# See wh|at we go|
|000018e0| 74 2e 0a 20 20 20 20 74 | 72 79 3a 0a 20 20 20 20 |t.. t|ry:. |
|000018f0| 20 20 20 20 69 66 20 74 | 79 70 65 20 3d 3d 20 69 | if t|ype == i|
|00001900| 6d 70 2e 43 5f 45 58 54 | 45 4e 53 49 4f 4e 3a 0a |mp.C_EXT|ENSION:.|
|00001910| 20 20 20 20 20 20 20 20 | 20 20 20 20 72 65 74 75 | | retu|
|00001920| 72 6e 20 69 6d 70 2e 6c | 6f 61 64 5f 64 79 6e 61 |rn imp.l|oad_dyna|
|00001930| 6d 69 63 28 6e 61 6d 65 | 2c 20 70 61 74 68 6e 61 |mic(name|, pathna|
|00001940| 6d 65 29 0a 20 20 20 20 | 20 20 20 20 69 66 20 74 |me). | if t|
|00001950| 79 70 65 20 3d 3d 20 69 | 6d 70 2e 50 59 5f 53 4f |ype == i|mp.PY_SO|
|00001960| 55 52 43 45 3a 0a 20 20 | 20 20 20 20 20 20 20 20 |URCE:. | |
|00001970| 20 20 72 65 74 75 72 6e | 20 69 6d 70 2e 6c 6f 61 | return| imp.loa|
|00001980| 64 5f 73 6f 75 72 63 65 | 28 6e 61 6d 65 2c 20 70 |d_source|(name, p|
|00001990| 61 74 68 6e 61 6d 65 2c | 20 66 70 29 0a 20 20 20 |athname,| fp). |
|000019a0| 20 20 20 20 20 69 66 20 | 74 79 70 65 20 3d 3d 20 | if |type == |
|000019b0| 69 6d 70 2e 50 59 5f 43 | 4f 4d 50 49 4c 45 44 3a |imp.PY_C|OMPILED:|
|000019c0| 0a 20 20 20 20 20 20 20 | 20 20 20 20 20 72 65 74 |. | ret|
|000019d0| 75 72 6e 20 69 6d 70 2e | 6c 6f 61 64 5f 63 6f 6d |urn imp.|load_com|
|000019e0| 70 69 6c 65 64 28 6e 61 | 6d 65 2c 20 70 61 74 68 |piled(na|me, path|
|000019f0| 6e 61 6d 65 2c 20 66 70 | 29 0a 0a 20 20 20 20 20 |name, fp|).. |
|00001a00| 20 20 20 23 20 53 68 6f | 75 6c 64 6e 27 74 20 67 | # Sho|uldn't g|
|00001a10| 65 74 20 68 65 72 65 20 | 61 74 20 61 6c 6c 2e 0a |et here |at all..|
|00001a20| 20 20 20 20 20 20 20 20 | 72 61 69 73 65 20 49 6d | |raise Im|
|00001a30| 70 6f 72 74 45 72 72 6f | 72 2c 20 27 25 73 3a 20 |portErro|r, '%s: |
|00001a40| 75 6e 6b 6e 6f 77 6e 20 | 6d 6f 64 75 6c 65 20 74 |unknown |module t|
|00001a50| 79 70 65 20 28 25 64 29 | 27 20 25 20 28 6e 61 6d |ype (%d)|' % (nam|
|00001a60| 65 2c 20 74 79 70 65 29 | 0a 20 20 20 20 66 69 6e |e, type)|. fin|
|00001a70| 61 6c 6c 79 3a 0a 20 20 | 20 20 20 20 20 20 23 20 |ally:. | # |
|00001a80| 53 69 6e 63 65 20 77 65 | 20 6d 61 79 20 65 78 69 |Since we| may exi|
|00001a90| 74 20 76 69 61 20 61 6e | 20 65 78 63 65 70 74 69 |t via an| excepti|
|00001aa0| 6f 6e 2c 20 63 6c 6f 73 | 65 20 66 70 20 65 78 70 |on, clos|e fp exp|
|00001ab0| 6c 69 63 69 74 6c 79 2e | 0a 20 20 20 20 20 20 20 |licitly.|. |
|00001ac0| 20 66 70 2e 63 6c 6f 73 | 65 28 29 0a 5c 65 6e 64 | fp.clos|e().\end|
|00001ad0| 7b 76 65 72 62 61 74 69 | 6d 7d 0a |{verbati|m}. |
+--------+-------------------------+-------------------------+--------+--------+