Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
2 | <html> | |
3 | <head> | |
4 | <link rel="STYLESHEET" href="lib.css" type='text/css' /> | |
5 | <link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" /> | |
6 | <link rel='start' href='../index.html' title='Python Documentation Index' /> | |
7 | <link rel="first" href="lib.html" title='Python Library Reference' /> | |
8 | <link rel='contents' href='contents.html' title="Contents" /> | |
9 | <link rel='index' href='genindex.html' title='Index' /> | |
10 | <link rel='last' href='about.html' title='About this document...' /> | |
11 | <link rel='help' href='about.html' title='About this document...' /> | |
12 | <link rel="next" href="node791.html" /> | |
13 | <link rel="prev" href="compiler.html" /> | |
14 | <link rel="parent" href="compiler.html" /> | |
15 | <link rel="next" href="node791.html" /> | |
16 | <meta name='aesop' content='information' /> | |
17 | <title>19.1 The basic interface</title> | |
18 | </head> | |
19 | <body> | |
20 | <DIV CLASS="navigation"> | |
21 | <div id='top-navigation-panel' xml:id='top-navigation-panel'> | |
22 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
23 | <tr> | |
24 | <td class='online-navigation'><a rel="prev" title="19. Python compiler package" | |
25 | href="compiler.html"><img src='../icons/previous.png' | |
26 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
27 | <td class='online-navigation'><a rel="parent" title="19. Python compiler package" | |
28 | href="compiler.html"><img src='../icons/up.png' | |
29 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
30 | <td class='online-navigation'><a rel="next" title="19.2 Limitations" | |
31 | href="node791.html"><img src='../icons/next.png' | |
32 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
33 | <td align="center" width="100%">Python Library Reference</td> | |
34 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
35 | href="contents.html"><img src='../icons/contents.png' | |
36 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
37 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' | |
38 | border='0' height='32' alt='Module Index' width='32' /></a></td> | |
39 | <td class='online-navigation'><a rel="index" title="Index" | |
40 | href="genindex.html"><img src='../icons/index.png' | |
41 | border='0' height='32' alt='Index' width='32' /></A></td> | |
42 | </tr></table> | |
43 | <div class='online-navigation'> | |
44 | <b class="navlabel">Previous:</b> | |
45 | <a class="sectref" rel="prev" href="compiler.html">19. Python compiler package</A> | |
46 | <b class="navlabel">Up:</b> | |
47 | <a class="sectref" rel="parent" href="compiler.html">19. Python compiler package</A> | |
48 | <b class="navlabel">Next:</b> | |
49 | <a class="sectref" rel="next" href="node791.html">19.2 Limitations</A> | |
50 | </div> | |
51 | <hr /></div> | |
52 | </DIV> | |
53 | <!--End of Navigation Panel--> | |
54 | ||
55 | <H1><A NAME="SECTION0021100000000000000000"> | |
56 | 19.1 The basic interface</A> | |
57 | </H1> | |
58 | ||
59 | <P> | |
60 | <A NAME="module-compiler"></A> | |
61 | <P> | |
62 | The top-level of the package defines four functions. If you import | |
63 | <tt class="module">compiler</tt>, you will get these functions and a collection of | |
64 | modules contained in the package. | |
65 | ||
66 | <P> | |
67 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
68 | <td><nobr><b><tt id='l2h-5020' xml:id='l2h-5020' class="function">parse</tt></b>(</nobr></td> | |
69 | <td><var>buf</var>)</td></tr></table></dt> | |
70 | <dd> | |
71 | Returns an abstract syntax tree for the Python source code in <var>buf</var>. | |
72 | The function raises SyntaxError if there is an error in the source | |
73 | code. The return value is a <tt class="class">compiler.ast.Module</tt> instance that | |
74 | contains the tree. | |
75 | </dl> | |
76 | ||
77 | <P> | |
78 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
79 | <td><nobr><b><tt id='l2h-5021' xml:id='l2h-5021' class="function">parseFile</tt></b>(</nobr></td> | |
80 | <td><var>path</var>)</td></tr></table></dt> | |
81 | <dd> | |
82 | Return an abstract syntax tree for the Python source code in the file | |
83 | specified by <var>path</var>. It is equivalent to | |
84 | <code>parse(open(<var>path</var>).read())</code>. | |
85 | </dl> | |
86 | ||
87 | <P> | |
88 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
89 | <td><nobr><b><tt id='l2h-5022' xml:id='l2h-5022' class="function">walk</tt></b>(</nobr></td> | |
90 | <td><var>ast, visitor</var><big>[</big><var>, verbose</var><big>]</big><var></var>)</td></tr></table></dt> | |
91 | <dd> | |
92 | Do a pre-order walk over the abstract syntax tree <var>ast</var>. Call the | |
93 | appropriate method on the <var>visitor</var> instance for each node | |
94 | encountered. | |
95 | </dl> | |
96 | ||
97 | <P> | |
98 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
99 | <td><nobr><b><tt id='l2h-5023' xml:id='l2h-5023' class="function">compile</tt></b>(</nobr></td> | |
100 | <td><var>source, filename, mode, flags=None, | |
101 | dont_inherit=None</var>)</td></tr></table></dt> | |
102 | <dd> | |
103 | Compile the string <var>source</var>, a Python module, statement or | |
104 | expression, into a code object that can be executed by the exec | |
105 | statement or <tt class="function">eval()</tt>. This function is a replacement for the | |
106 | built-in <tt class="function">compile()</tt> function. | |
107 | ||
108 | <P> | |
109 | The <var>filename</var> will be used for run-time error messages. | |
110 | ||
111 | <P> | |
112 | The <var>mode</var> must be 'exec' to compile a module, 'single' to compile a | |
113 | single (interactive) statement, or 'eval' to compile an expression. | |
114 | ||
115 | <P> | |
116 | The <var>flags</var> and <var>dont_inherit</var> arguments affect future-related | |
117 | statements, but are not supported yet. | |
118 | </dl> | |
119 | ||
120 | <P> | |
121 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
122 | <td><nobr><b><tt id='l2h-5024' xml:id='l2h-5024' class="function">compileFile</tt></b>(</nobr></td> | |
123 | <td><var>source</var>)</td></tr></table></dt> | |
124 | <dd> | |
125 | Compiles the file <var>source</var> and generates a .pyc file. | |
126 | </dl> | |
127 | ||
128 | <P> | |
129 | The <tt class="module">compiler</tt> package contains the following modules: | |
130 | <tt class="module"><a href="module-compiler.ast.html">ast</a></tt>, <tt class="module">consts</tt>, <tt class="module">future</tt>, | |
131 | <tt class="module">misc</tt>, <tt class="module">pyassem</tt>, <tt class="module">pycodegen</tt>, <tt class="module">symbols</tt>, | |
132 | <tt class="module">transformer</tt>, and <tt class="module"><a href="module-compiler.visitor.html">visitor</a></tt>. | |
133 | ||
134 | <P> | |
135 | ||
136 | <DIV CLASS="navigation"> | |
137 | <div class='online-navigation'> | |
138 | <p></p><hr /> | |
139 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
140 | <tr> | |
141 | <td class='online-navigation'><a rel="prev" title="19. Python compiler package" | |
142 | href="compiler.html"><img src='../icons/previous.png' | |
143 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
144 | <td class='online-navigation'><a rel="parent" title="19. Python compiler package" | |
145 | href="compiler.html"><img src='../icons/up.png' | |
146 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
147 | <td class='online-navigation'><a rel="next" title="19.2 Limitations" | |
148 | href="node791.html"><img src='../icons/next.png' | |
149 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
150 | <td align="center" width="100%">Python Library Reference</td> | |
151 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
152 | href="contents.html"><img src='../icons/contents.png' | |
153 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
154 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' | |
155 | border='0' height='32' alt='Module Index' width='32' /></a></td> | |
156 | <td class='online-navigation'><a rel="index" title="Index" | |
157 | href="genindex.html"><img src='../icons/index.png' | |
158 | border='0' height='32' alt='Index' width='32' /></A></td> | |
159 | </tr></table> | |
160 | <div class='online-navigation'> | |
161 | <b class="navlabel">Previous:</b> | |
162 | <a class="sectref" rel="prev" href="compiler.html">19. Python compiler package</A> | |
163 | <b class="navlabel">Up:</b> | |
164 | <a class="sectref" rel="parent" href="compiler.html">19. Python compiler package</A> | |
165 | <b class="navlabel">Next:</b> | |
166 | <a class="sectref" rel="next" href="node791.html">19.2 Limitations</A> | |
167 | </div> | |
168 | </div> | |
169 | <hr /> | |
170 | <span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span> | |
171 | </DIV> | |
172 | <!--End of Navigation Panel--> | |
173 | <ADDRESS> | |
174 | See <i><a href="about.html">About this document...</a></i> for information on suggesting changes. | |
175 | </ADDRESS> | |
176 | </BODY> | |
177 | </HTML> |