| 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
| 2 | <html> |
| 3 | <head> |
| 4 | <link rel="STYLESHEET" href="api.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="api.html" title='Python/C API Reference Manual' /> |
| 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="countingRefs.html" /> |
| 13 | <link rel="prev" href="intro.html" /> |
| 14 | <link rel="parent" href="api.html" /> |
| 15 | <link rel="next" href="countingRefs.html" /> |
| 16 | <meta name='aesop' content='information' /> |
| 17 | <title>2. The Very High Level Layer </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="1.4 Embedding Python" |
| 25 | href="embedding.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="Python/C API Reference Manual" |
| 28 | href="api.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="3. Reference Counting" |
| 31 | href="countingRefs.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/C API Reference Manual</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'><img src='../icons/blank.png' |
| 38 | border='0' height='32' alt='' width='32' /></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="embedding.html">1.4 Embedding Python</A> |
| 46 | <b class="navlabel">Up:</b> |
| 47 | <a class="sectref" rel="parent" href="api.html">Python/C API Reference Manual</A> |
| 48 | <b class="navlabel">Next:</b> |
| 49 | <a class="sectref" rel="next" href="countingRefs.html">3. Reference Counting</A> |
| 50 | </div> |
| 51 | <hr /></div> |
| 52 | </DIV> |
| 53 | <!--End of Navigation Panel--> |
| 54 | |
| 55 | <H1><A NAME="SECTION004000000000000000000"></A><A NAME="veryhigh"></A> |
| 56 | <BR> |
| 57 | 2. The Very High Level Layer |
| 58 | </H1> |
| 59 | |
| 60 | <P> |
| 61 | The functions in this chapter will let you execute Python source code |
| 62 | given in a file or a buffer, but they will not let you interact in a |
| 63 | more detailed way with the interpreter. |
| 64 | |
| 65 | <P> |
| 66 | Several of these functions accept a start symbol from the grammar as a |
| 67 | parameter. The available start symbols are <tt class="constant">Py_eval_input</tt>, |
| 68 | <tt class="constant">Py_file_input</tt>, and <tt class="constant">Py_single_input</tt>. These are |
| 69 | described following the functions which accept them as parameters. |
| 70 | |
| 71 | <P> |
| 72 | Note also that several of these functions take <tt class="ctype">FILE*</tt> |
| 73 | parameters. On particular issue which needs to be handled carefully |
| 74 | is that the <tt class="ctype">FILE</tt> structure for different C libraries can be |
| 75 | different and incompatible. Under Windows (at least), it is possible |
| 76 | for dynamically linked extensions to actually use different libraries, |
| 77 | so care should be taken that <tt class="ctype">FILE*</tt> parameters are only passed |
| 78 | to these functions if it is certain that they were created by the same |
| 79 | library that the Python runtime is using. |
| 80 | |
| 81 | <P> |
| 82 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>int <b><tt id='l2h-48' xml:id='l2h-48' class="cfunction">Py_Main</tt></b>(</nobr></td><td>int <var>argc</var>, char **<var>argv</var>)</td></tr></table></dt> |
| 83 | <dd> |
| 84 | The main program for the standard interpreter. This is made |
| 85 | available for programs which embed Python. The <var>argc</var> and |
| 86 | <var>argv</var> parameters should be prepared exactly as those which are |
| 87 | passed to a C program's <tt class="cfunction">main()</tt> function. It is |
| 88 | important to note that the argument list may be modified (but the |
| 89 | contents of the strings pointed to by the argument list are not). |
| 90 | The return value will be the integer passed to the |
| 91 | <tt class="function">sys.exit()</tt> function, <code>1</code> if the interpreter exits |
| 92 | due to an exception, or <code>2</code> if the parameter list does not |
| 93 | represent a valid Python command line. |
| 94 | </dd></dl> |
| 95 | |
| 96 | <P> |
| 97 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>int <b><tt id='l2h-49' xml:id='l2h-49' class="cfunction">PyRun_AnyFile</tt></b>(</nobr></td><td>FILE *<var>fp</var>, const char *<var>filename</var>)</td></tr></table></dt> |
| 98 | <dd> |
| 99 | This is a simplified interface to <tt class="cfunction">PyRun_AnyFileExFlags()</tt> |
| 100 | below, leaving <var>closeit</var> set to <code>0</code> and <var>flags</var> set to <tt class="constant">NULL</tt>. |
| 101 | </dd></dl> |
| 102 | |
| 103 | <P> |
| 104 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>int <b><tt id='l2h-50' xml:id='l2h-50' class="cfunction">PyRun_AnyFileFlags</tt></b>(</nobr></td><td>FILE *<var>fp</var>, const char *<var>filename</var>, |
| 105 | PyCompilerFlags *<var>flags</var>)</td></tr></table></dt> |
| 106 | <dd> |
| 107 | This is a simplified interface to <tt class="cfunction">PyRun_AnyFileExFlags()</tt> |
| 108 | below, leaving the <var>closeit</var> argument set to <code>0</code>. |
| 109 | </dd></dl> |
| 110 | |
| 111 | <P> |
| 112 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>int <b><tt id='l2h-51' xml:id='l2h-51' class="cfunction">PyRun_AnyFileEx</tt></b>(</nobr></td><td>FILE *<var>fp</var>, const char *<var>filename</var>, |
| 113 | int <var>closeit</var>)</td></tr></table></dt> |
| 114 | <dd> |
| 115 | This is a simplified interface to <tt class="cfunction">PyRun_AnyFileExFlags()</tt> |
| 116 | below, leaving the <var>flags</var> argument set to <tt class="constant">NULL</tt>. |
| 117 | </dd></dl> |
| 118 | |
| 119 | <P> |
| 120 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>int <b><tt id='l2h-52' xml:id='l2h-52' class="cfunction">PyRun_AnyFileExFlags</tt></b>(</nobr></td><td>FILE *<var>fp</var>, const char *<var>filename</var>, |
| 121 | int <var>closeit</var>, |
| 122 | PyCompilerFlags *<var>flags</var>)</td></tr></table></dt> |
| 123 | <dd> |
| 124 | If <var>fp</var> refers to a file associated with an interactive device |
| 125 | (console or terminal input or <span class="Unix">Unix</span> pseudo-terminal), return the |
| 126 | value of <tt class="cfunction">PyRun_InteractiveLoop()</tt>, otherwise return the |
| 127 | result of <tt class="cfunction">PyRun_SimpleFile()</tt>. If <var>filename</var> is |
| 128 | <tt class="constant">NULL</tt>, this function uses <code>"???"</code> as the filename. |
| 129 | </dd></dl> |
| 130 | |
| 131 | <P> |
| 132 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>int <b><tt id='l2h-53' xml:id='l2h-53' class="cfunction">PyRun_SimpleString</tt></b>(</nobr></td><td>const char *<var>command</var>)</td></tr></table></dt> |
| 133 | <dd> |
| 134 | This is a simplified interface to <tt class="cfunction">PyRun_SimpleStringFlags()</tt> |
| 135 | below, leaving the <var>PyCompilerFlags*</var> argument set to NULL. |
| 136 | </dd></dl> |
| 137 | |
| 138 | <P> |
| 139 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>int <b><tt id='l2h-54' xml:id='l2h-54' class="cfunction">PyRun_SimpleStringFlags</tt></b>(</nobr></td><td>const char *<var>command</var>, |
| 140 | PyCompilerFlags *<var>flags</var>)</td></tr></table></dt> |
| 141 | <dd> |
| 142 | Executes the Python source code from <var>command</var> in the |
| 143 | <tt class="module">__main__</tt> module according to the <var>flags</var> argument. |
| 144 | If <tt class="module">__main__</tt> does not already exist, it is created. Returns |
| 145 | <code>0</code> on success or <code>-1</code> if an exception was raised. If there |
| 146 | was an error, there is no way to get the exception information. |
| 147 | For the meaning of <var>flags</var>, see below. |
| 148 | </dd></dl> |
| 149 | |
| 150 | <P> |
| 151 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>int <b><tt id='l2h-55' xml:id='l2h-55' class="cfunction">PyRun_SimpleFile</tt></b>(</nobr></td><td>FILE *<var>fp</var>, const char *<var>filename</var>)</td></tr></table></dt> |
| 152 | <dd> |
| 153 | This is a simplified interface to <tt class="cfunction">PyRun_SimpleFileExFlags()</tt> |
| 154 | below, leaving <var>closeit</var> set to <code>0</code> and <var>flags</var> set to |
| 155 | <tt class="constant">NULL</tt>. |
| 156 | </dd></dl> |
| 157 | |
| 158 | <P> |
| 159 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>int <b><tt id='l2h-56' xml:id='l2h-56' class="cfunction">PyRun_SimpleFileFlags</tt></b>(</nobr></td><td>FILE *<var>fp</var>, const char *<var>filename</var>, |
| 160 | PyCompilerFlags *<var>flags</var>)</td></tr></table></dt> |
| 161 | <dd> |
| 162 | This is a simplified interface to <tt class="cfunction">PyRun_SimpleFileExFlags()</tt> |
| 163 | below, leaving <var>closeit</var> set to <code>0</code>. |
| 164 | </dd></dl> |
| 165 | |
| 166 | <P> |
| 167 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>int <b><tt id='l2h-57' xml:id='l2h-57' class="cfunction">PyRun_SimpleFileEx</tt></b>(</nobr></td><td>FILE *<var>fp</var>, const char *<var>filename</var>, |
| 168 | int <var>closeit</var>)</td></tr></table></dt> |
| 169 | <dd> |
| 170 | This is a simplified interface to <tt class="cfunction">PyRun_SimpleFileExFlags()</tt> |
| 171 | below, leaving <var>flags</var> set to <tt class="constant">NULL</tt>. |
| 172 | </dd></dl> |
| 173 | |
| 174 | <P> |
| 175 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>int <b><tt id='l2h-58' xml:id='l2h-58' class="cfunction">PyRun_SimpleFileExFlags</tt></b>(</nobr></td><td>FILE *<var>fp</var>, const char *<var>filename</var>, |
| 176 | int <var>closeit</var>, |
| 177 | PyCompilerFlags *<var>flags</var>)</td></tr></table></dt> |
| 178 | <dd> |
| 179 | Similar to <tt class="cfunction">PyRun_SimpleStringFlags()</tt>, but the Python source |
| 180 | code is read from <var>fp</var> instead of an in-memory string. |
| 181 | <var>filename</var> should be the name of the file. If <var>closeit</var> is |
| 182 | true, the file is closed before PyRun_SimpleFileExFlags returns. |
| 183 | </dd></dl> |
| 184 | |
| 185 | <P> |
| 186 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>int <b><tt id='l2h-59' xml:id='l2h-59' class="cfunction">PyRun_InteractiveOne</tt></b>(</nobr></td><td>FILE *<var>fp</var>, const char *<var>filename</var>)</td></tr></table></dt> |
| 187 | <dd> |
| 188 | This is a simplified interface to <tt class="cfunction">PyRun_InteractiveOneFlags()</tt> |
| 189 | below, leaving <var>flags</var> set to <tt class="constant">NULL</tt>. |
| 190 | </dd></dl> |
| 191 | |
| 192 | <P> |
| 193 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>int <b><tt id='l2h-60' xml:id='l2h-60' class="cfunction">PyRun_InteractiveOneFlags</tt></b>(</nobr></td><td>FILE *<var>fp</var>, |
| 194 | const char *<var>filename</var>, |
| 195 | PyCompilerFlags *<var>flags</var>)</td></tr></table></dt> |
| 196 | <dd> |
| 197 | Read and execute a single statement from a file associated with an |
| 198 | interactive device according to the <var>flags</var> argument. If |
| 199 | <var>filename</var> is <tt class="constant">NULL</tt>, <code>"???"</code> is used instead. The user will |
| 200 | be prompted using <code>sys.ps1</code> and <code>sys.ps2</code>. Returns <code>0</code> |
| 201 | when the input was executed successfully, <code>-1</code> if there was an |
| 202 | exception, or an error code from the <span class="file">errcode.h</span> include file |
| 203 | distributed as part of Python if there was a parse error. (Note that |
| 204 | <span class="file">errcode.h</span> is not included by <span class="file">Python.h</span>, so must be included |
| 205 | specifically if needed.) |
| 206 | </dd></dl> |
| 207 | |
| 208 | <P> |
| 209 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>int <b><tt id='l2h-61' xml:id='l2h-61' class="cfunction">PyRun_InteractiveLoop</tt></b>(</nobr></td><td>FILE *<var>fp</var>, const char *<var>filename</var>)</td></tr></table></dt> |
| 210 | <dd> |
| 211 | This is a simplified interface to <tt class="cfunction">PyRun_InteractiveLoopFlags()</tt> |
| 212 | below, leaving <var>flags</var> set to <tt class="constant">NULL</tt>. |
| 213 | </dd></dl> |
| 214 | |
| 215 | <P> |
| 216 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>int <b><tt id='l2h-62' xml:id='l2h-62' class="cfunction">PyRun_InteractiveLoopFlags</tt></b>(</nobr></td><td>FILE *<var>fp</var>, |
| 217 | const char *<var>filename</var>, |
| 218 | PyCompilerFlags *<var>flags</var>)</td></tr></table></dt> |
| 219 | <dd> |
| 220 | Read and execute statements from a file associated with an |
| 221 | interactive device until EOF is reached. If <var>filename</var> is |
| 222 | <tt class="constant">NULL</tt>, <code>"???"</code> is used instead. The user will be prompted |
| 223 | using <code>sys.ps1</code> and <code>sys.ps2</code>. Returns <code>0</code> at EOF. |
| 224 | </dd></dl> |
| 225 | |
| 226 | <P> |
| 227 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>struct _node* <b><tt id='l2h-63' xml:id='l2h-63' class="cfunction">PyParser_SimpleParseString</tt></b>(</nobr></td><td>const char *<var>str</var>, |
| 228 | int <var>start</var>)</td></tr></table></dt> |
| 229 | <dd> |
| 230 | This is a simplified interface to |
| 231 | <tt class="cfunction">PyParser_SimpleParseStringFlagsFilename()</tt> below, leaving |
| 232 | <var>filename</var> set to <tt class="constant">NULL</tt> and <var>flags</var> set to <code>0</code>. |
| 233 | </dd></dl> |
| 234 | |
| 235 | <P> |
| 236 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>struct _node* <b><tt id='l2h-64' xml:id='l2h-64' class="cfunction">PyParser_SimpleParseStringFlags</tt></b>(</nobr></td><td> |
| 237 | const char *<var>str</var>, int <var>start</var>, int <var>flags</var>)</td></tr></table></dt> |
| 238 | <dd> |
| 239 | This is a simplified interface to |
| 240 | <tt class="cfunction">PyParser_SimpleParseStringFlagsFilename()</tt> below, leaving |
| 241 | <var>filename</var> set to <tt class="constant">NULL</tt>. |
| 242 | </dd></dl> |
| 243 | |
| 244 | <P> |
| 245 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>struct _node* <b><tt id='l2h-65' xml:id='l2h-65' class="cfunction">PyParser_SimpleParseStringFlagsFilename</tt></b>(</nobr></td><td> |
| 246 | const char *<var>str</var>, const char *<var>filename</var>, |
| 247 | int <var>start</var>, int <var>flags</var>)</td></tr></table></dt> |
| 248 | <dd> |
| 249 | Parse Python source code from <var>str</var> using the start token |
| 250 | <var>start</var> according to the <var>flags</var> argument. The result can |
| 251 | be used to create a code object which can be evaluated efficiently. |
| 252 | This is useful if a code fragment must be evaluated many times. |
| 253 | </dd></dl> |
| 254 | |
| 255 | <P> |
| 256 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>struct _node* <b><tt id='l2h-66' xml:id='l2h-66' class="cfunction">PyParser_SimpleParseFile</tt></b>(</nobr></td><td>FILE *<var>fp</var>, |
| 257 | const char *<var>filename</var>, int <var>start</var>)</td></tr></table></dt> |
| 258 | <dd> |
| 259 | This is a simplified interface to <tt class="cfunction">PyParser_SimpleParseFileFlags()</tt> |
| 260 | below, leaving <var>flags</var> set to <code>0</code> |
| 261 | </dd></dl> |
| 262 | |
| 263 | <P> |
| 264 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>struct _node* <b><tt id='l2h-67' xml:id='l2h-67' class="cfunction">PyParser_SimpleParseFileFlags</tt></b>(</nobr></td><td>FILE *<var>fp</var>, |
| 265 | const char *<var>filename</var>, int <var>start</var>, int <var>flags</var>)</td></tr></table></dt> |
| 266 | <dd> |
| 267 | Similar to <tt class="cfunction">PyParser_SimpleParseStringFlagsFilename()</tt>, but |
| 268 | the Python source code is read from <var>fp</var> instead of an in-memory |
| 269 | string. |
| 270 | </dd></dl> |
| 271 | |
| 272 | <P> |
| 273 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject* <b><tt id='l2h-68' xml:id='l2h-68' class="cfunction">PyRun_String</tt></b>(</nobr></td><td>const char *<var>str</var>, int <var>start</var>, |
| 274 | PyObject *<var>globals</var>, |
| 275 | PyObject *<var>locals</var>)</td></tr></table></dt> |
| 276 | <dd> |
| 277 | <div class="refcount-info"> |
| 278 | <span class="label">Return value:</span> |
| 279 | <span class="value">New reference.</span> |
| 280 | </div> |
| 281 | This is a simplified interface to <tt class="cfunction">PyRun_StringFlags()</tt> below, |
| 282 | leaving <var>flags</var> set to <tt class="constant">NULL</tt>. |
| 283 | </dd></dl> |
| 284 | |
| 285 | <P> |
| 286 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject* <b><tt id='l2h-69' xml:id='l2h-69' class="cfunction">PyRun_StringFlags</tt></b>(</nobr></td><td>const char *<var>str</var>, int <var>start</var>, |
| 287 | PyObject *<var>globals</var>, |
| 288 | PyObject *<var>locals</var>, |
| 289 | PyCompilerFlags *<var>flags</var>)</td></tr></table></dt> |
| 290 | <dd> |
| 291 | Execute Python source code from <var>str</var> in the context specified |
| 292 | by the dictionaries <var>globals</var> and <var>locals</var> with the compiler |
| 293 | flags specified by <var>flags</var>. The parameter <var>start</var> specifies |
| 294 | the start token that should be used to parse the source code. |
| 295 | |
| 296 | <P> |
| 297 | Returns the result of executing the code as a Python object, or |
| 298 | <tt class="constant">NULL</tt> if an exception was raised. |
| 299 | </dd></dl> |
| 300 | |
| 301 | <P> |
| 302 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject* <b><tt id='l2h-70' xml:id='l2h-70' class="cfunction">PyRun_File</tt></b>(</nobr></td><td>FILE *<var>fp</var>, const char *<var>filename</var>, |
| 303 | int <var>start</var>, PyObject *<var>globals</var>, |
| 304 | PyObject *<var>locals</var>)</td></tr></table></dt> |
| 305 | <dd> |
| 306 | <div class="refcount-info"> |
| 307 | <span class="label">Return value:</span> |
| 308 | <span class="value">New reference.</span> |
| 309 | </div> |
| 310 | This is a simplified interface to <tt class="cfunction">PyRun_FileExFlags()</tt> below, |
| 311 | leaving <var>closeit</var> set to <code>0</code> and <var>flags</var> set to <tt class="constant">NULL</tt>. |
| 312 | </dd></dl> |
| 313 | |
| 314 | <P> |
| 315 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject* <b><tt id='l2h-71' xml:id='l2h-71' class="cfunction">PyRun_FileEx</tt></b>(</nobr></td><td>FILE *<var>fp</var>, const char *<var>filename</var>, |
| 316 | int <var>start</var>, PyObject *<var>globals</var>, |
| 317 | PyObject *<var>locals</var>, int <var>closeit</var>)</td></tr></table></dt> |
| 318 | <dd> |
| 319 | This is a simplified interface to <tt class="cfunction">PyRun_FileExFlags()</tt> below, |
| 320 | leaving <var>flags</var> set to <tt class="constant">NULL</tt>. |
| 321 | </dd></dl> |
| 322 | |
| 323 | <P> |
| 324 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject* <b><tt id='l2h-72' xml:id='l2h-72' class="cfunction">PyRun_FileFlags</tt></b>(</nobr></td><td>FILE *<var>fp</var>, const char *<var>filename</var>, |
| 325 | int <var>start</var>, PyObject *<var>globals</var>, |
| 326 | PyObject *<var>locals</var>, |
| 327 | PyCompilerFlags *<var>flags</var>)</td></tr></table></dt> |
| 328 | <dd> |
| 329 | This is a simplified interface to <tt class="cfunction">PyRun_FileExFlags()</tt> below, |
| 330 | leaving <var>closeit</var> set to <code>0</code>. |
| 331 | </dd></dl> |
| 332 | |
| 333 | <P> |
| 334 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject* <b><tt id='l2h-73' xml:id='l2h-73' class="cfunction">PyRun_FileExFlags</tt></b>(</nobr></td><td>FILE *<var>fp</var>, const char *<var>filename</var>, |
| 335 | int <var>start</var>, PyObject *<var>globals</var>, |
| 336 | PyObject *<var>locals</var>, int <var>closeit</var>, |
| 337 | PyCompilerFlags *<var>flags</var>)</td></tr></table></dt> |
| 338 | <dd> |
| 339 | Similar to <tt class="cfunction">PyRun_StringFlags()</tt>, but the Python source code is |
| 340 | read from <var>fp</var> instead of an in-memory string. |
| 341 | <var>filename</var> should be the name of the file. |
| 342 | If <var>closeit</var> is true, the file is closed before |
| 343 | <tt class="cfunction">PyRun_FileExFlags()</tt> returns. |
| 344 | </dd></dl> |
| 345 | |
| 346 | <P> |
| 347 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject* <b><tt id='l2h-74' xml:id='l2h-74' class="cfunction">Py_CompileString</tt></b>(</nobr></td><td>const char *<var>str</var>, |
| 348 | const char *<var>filename</var>, |
| 349 | int <var>start</var>)</td></tr></table></dt> |
| 350 | <dd> |
| 351 | <div class="refcount-info"> |
| 352 | <span class="label">Return value:</span> |
| 353 | <span class="value">New reference.</span> |
| 354 | </div> |
| 355 | This is a simplified interface to <tt class="cfunction">Py_CompileStringFlags()</tt> below, |
| 356 | leaving <var>flags</var> set to <tt class="constant">NULL</tt>. |
| 357 | </dd></dl> |
| 358 | |
| 359 | <P> |
| 360 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"><td><nobr>PyObject* <b><tt id='l2h-75' xml:id='l2h-75' class="cfunction">Py_CompileStringFlags</tt></b>(</nobr></td><td>const char *<var>str</var>, |
| 361 | const char *<var>filename</var>, |
| 362 | int <var>start</var>, |
| 363 | PyCompilerFlags *<var>flags</var>)</td></tr></table></dt> |
| 364 | <dd> |
| 365 | Parse and compile the Python source code in <var>str</var>, returning the |
| 366 | resulting code object. The start token is given by <var>start</var>; |
| 367 | this can be used to constrain the code which can be compiled and should |
| 368 | be <tt class="constant">Py_eval_input</tt>, <tt class="constant">Py_file_input</tt>, or |
| 369 | <tt class="constant">Py_single_input</tt>. The filename specified by |
| 370 | <var>filename</var> is used to construct the code object and may appear |
| 371 | in tracebacks or <tt class="exception">SyntaxError</tt> exception messages. This |
| 372 | returns <tt class="constant">NULL</tt> if the code cannot be parsed or compiled. |
| 373 | </dd></dl> |
| 374 | |
| 375 | <P> |
| 376 | <dl><dt>int <b><tt id='l2h-76' xml:id='l2h-76' class="cdata">Py_eval_input</tt></b></dt> |
| 377 | <dd> |
| 378 | The start symbol from the Python grammar for isolated expressions; |
| 379 | for use with |
| 380 | <tt class="cfunction">Py_CompileString()</tt><a id='l2h-81' xml:id='l2h-81'></a>. |
| 381 | </dd></dl> |
| 382 | |
| 383 | <P> |
| 384 | <dl><dt>int <b><tt id='l2h-77' xml:id='l2h-77' class="cdata">Py_file_input</tt></b></dt> |
| 385 | <dd> |
| 386 | The start symbol from the Python grammar for sequences of statements |
| 387 | as read from a file or other source; for use with |
| 388 | <tt class="cfunction">Py_CompileString()</tt><a id='l2h-82' xml:id='l2h-82'></a>. This is |
| 389 | the symbol to use when compiling arbitrarily long Python source code. |
| 390 | </dd></dl> |
| 391 | |
| 392 | <P> |
| 393 | <dl><dt>int <b><tt id='l2h-78' xml:id='l2h-78' class="cdata">Py_single_input</tt></b></dt> |
| 394 | <dd> |
| 395 | The start symbol from the Python grammar for a single statement; for |
| 396 | use with <tt class="cfunction">Py_CompileString()</tt><a id='l2h-83' xml:id='l2h-83'></a>. |
| 397 | This is the symbol used for the interactive interpreter loop. |
| 398 | </dd></dl> |
| 399 | |
| 400 | <P> |
| 401 | <dl><dt><b><tt class="ctype"><a id='l2h-79' xml:id='l2h-79'>struct PyCompilerFlags</a></tt></b></dt> |
| 402 | <dd> |
| 403 | This is the structure used to hold compiler flags. In cases where |
| 404 | code is only being compiled, it is passed as <code>int flags</code>, and in |
| 405 | cases where code is being executed, it is passed as |
| 406 | <code>PyCompilerFlags *flags</code>. In this case, <code>from __future__ |
| 407 | import</code> can modify <var>flags</var>. |
| 408 | |
| 409 | <P> |
| 410 | Whenever <code>PyCompilerFlags *flags</code> is <tt class="constant">NULL</tt>, <tt class="member">cf_flags</tt> |
| 411 | is treated as equal to <code>0</code>, and any modification due to |
| 412 | <code>from __future__ import</code> is discarded. |
| 413 | <div class="verbatim"><pre> |
| 414 | struct PyCompilerFlags { |
| 415 | int cf_flags; |
| 416 | } |
| 417 | </pre></div> |
| 418 | </dl> |
| 419 | |
| 420 | <P> |
| 421 | <dl><dt>int <b><tt id='l2h-80' xml:id='l2h-80' class="cdata">CO_FUTURE_DIVISION</tt></b></dt> |
| 422 | <dd> |
| 423 | This bit can be set in <var>flags</var> to cause division operator <code>/</code> |
| 424 | to be interpreted as ``true division'' according to <a class="rfc" id='rfcref-13090' xml:id='rfcref-13090' |
| 425 | href="http://www.python.org/peps/pep-0238.html">PEP 238</a>. |
| 426 | </dd></dl> |
| 427 | |
| 428 | <DIV CLASS="navigation"> |
| 429 | <div class='online-navigation'> |
| 430 | <p></p><hr /> |
| 431 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> |
| 432 | <tr> |
| 433 | <td class='online-navigation'><a rel="prev" title="1.4 Embedding Python" |
| 434 | href="embedding.html"><img src='../icons/previous.png' |
| 435 | border='0' height='32' alt='Previous Page' width='32' /></A></td> |
| 436 | <td class='online-navigation'><a rel="parent" title="Python/C API Reference Manual" |
| 437 | href="api.html"><img src='../icons/up.png' |
| 438 | border='0' height='32' alt='Up One Level' width='32' /></A></td> |
| 439 | <td class='online-navigation'><a rel="next" title="3. Reference Counting" |
| 440 | href="countingRefs.html"><img src='../icons/next.png' |
| 441 | border='0' height='32' alt='Next Page' width='32' /></A></td> |
| 442 | <td align="center" width="100%">Python/C API Reference Manual</td> |
| 443 | <td class='online-navigation'><a rel="contents" title="Table of Contents" |
| 444 | href="contents.html"><img src='../icons/contents.png' |
| 445 | border='0' height='32' alt='Contents' width='32' /></A></td> |
| 446 | <td class='online-navigation'><img src='../icons/blank.png' |
| 447 | border='0' height='32' alt='' width='32' /></td> |
| 448 | <td class='online-navigation'><a rel="index" title="Index" |
| 449 | href="genindex.html"><img src='../icons/index.png' |
| 450 | border='0' height='32' alt='Index' width='32' /></A></td> |
| 451 | </tr></table> |
| 452 | <div class='online-navigation'> |
| 453 | <b class="navlabel">Previous:</b> |
| 454 | <a class="sectref" rel="prev" href="embedding.html">1.4 Embedding Python</A> |
| 455 | <b class="navlabel">Up:</b> |
| 456 | <a class="sectref" rel="parent" href="api.html">Python/C API Reference Manual</A> |
| 457 | <b class="navlabel">Next:</b> |
| 458 | <a class="sectref" rel="next" href="countingRefs.html">3. Reference Counting</A> |
| 459 | </div> |
| 460 | </div> |
| 461 | <hr /> |
| 462 | <span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span> |
| 463 | </DIV> |
| 464 | <!--End of Navigation Panel--> |
| 465 | <ADDRESS> |
| 466 | See <i><a href="about.html">About this document...</a></i> for information on suggesting changes. |
| 467 | </ADDRESS> |
| 468 | </BODY> |
| 469 | </HTML> |