| file or a buffer, but they will not let you interact in a more detailed way with |
| the interpreter. |
| |
| Several of these functions accept a start symbol from the grammar as a |
| parameter. The available start symbols are :const:`Py_eval_input`, |
| :const:`Py_file_input`, and :const:`Py_single_input`. These are described |
| following the functions which accept them as parameters. |
| |
n | Note also that several of these functions take :ctype:`FILE\*` parameters. On |
n | Note also that several of these functions take :ctype:`FILE\*` parameters. One |
| particular issue which needs to be handled carefully is that the :ctype:`FILE` |
| structure for different C libraries can be different and incompatible. Under |
| Windows (at least), it is possible for dynamically linked extensions to actually |
| use different libraries, so care should be taken that :ctype:`FILE\*` parameters |
| are only passed to these functions if it is certain that they were created by |
| the same library that the Python runtime is using. |
| |
| |
| programs which embed Python. The *argc* and *argv* parameters should be |
| prepared exactly as those which are passed to a C program's :cfunc:`main` |
| function. It is important to note that the argument list may be modified (but |
| the contents of the strings pointed to by the argument list are not). The return |
| value will be the integer passed to the :func:`sys.exit` function, ``1`` if the |
| interpreter exits due to an exception, or ``2`` if the parameter list does not |
| represent a valid Python command line. |
| |
n | Note that if an otherwise unhandled :exc:`SystemError` is raised, this |
| function will not return ``1``, but exit the process, as long as |
| ``Py_InspectFlag`` is not set. |
| |
| |
| .. cfunction:: int PyRun_AnyFile(FILE *fp, const char *filename) |
| |
| This is a simplified interface to :cfunc:`PyRun_AnyFileExFlags` below, leaving |
| *closeit* set to ``0`` and *flags* set to *NULL*. |
| |
| |
| .. cfunction:: int PyRun_AnyFileFlags(FILE *fp, const char *filename, PyCompilerFlags *flags) |
| |
| .. cfunction:: int PyRun_SimpleStringFlags(const char *command, PyCompilerFlags *flags) |
| |
| Executes the Python source code from *command* in the :mod:`__main__` module |
| according to the *flags* argument. If :mod:`__main__` does not already exist, it |
| is created. Returns ``0`` on success or ``-1`` if an exception was raised. If |
| there was an error, there is no way to get the exception information. For the |
| meaning of *flags*, see below. |
n | |
| Note that if an otherwise unhandled :exc:`SystemError` is raised, this |
| function will not return ``-1``, but exit the process, as long as |
| ``Py_InspectFlag`` is not set. |
| |
| |
| .. cfunction:: int PyRun_SimpleFile(FILE *fp, const char *filename) |
| |
| This is a simplified interface to :cfunc:`PyRun_SimpleFileExFlags` below, |
| leaving *closeit* set to ``0`` and *flags* set to *NULL*. |
| |
| |
| object. The start token is given by *start*; this can be used to constrain the |
| code which can be compiled and should be :const:`Py_eval_input`, |
| :const:`Py_file_input`, or :const:`Py_single_input`. The filename specified by |
| *filename* is used to construct the code object and may appear in tracebacks or |
| :exc:`SyntaxError` exception messages. This returns *NULL* if the code cannot |
| be parsed or compiled. |
| |
| |
t | .. cfunction:: PyObject* PyEval_EvalCode(PyCodeObject *co, PyObject *globals, PyObject *locals) |
| |
| This is a simplified interface to :cfunc:`PyEval_EvalCodeEx`, with just |
| the code object, and the dictionaries of global and local variables. |
| The other arguments are set to *NULL*. |
| |
| |
| .. cfunction:: PyObject* PyEval_EvalCodeEx(PyCodeObject *co, PyObject *globals, PyObject *locals, PyObject **args, int argcount, PyObject **kws, int kwcount, PyObject **defs, int defcount, PyObject *closure) |
| |
| Evaluate a precompiled code object, given a particular environment for its |
| evaluation. This environment consists of dictionaries of global and local |
| variables, arrays of arguments, keywords and defaults, and a closure tuple of |
| cells. |
| |
| |
| .. cfunction:: PyObject* PyEval_EvalFrame(PyFrameObject *f) |
| |
| Evaluate an execution frame. This is a simplified interface to |
| PyEval_EvalFrameEx, for backward compatibility. |
| |
| |
| .. cfunction:: PyObject* PyEval_EvalFrameEx(PyFrameObject *f, int throwflag) |
| |
| This is the main, unvarnished function of Python interpretation. It is |
| literally 2000 lines long. The code object associated with the execution |
| frame *f* is executed, interpreting bytecode and executing calls as needed. |
| The additional *throwflag* parameter can mostly be ignored - if true, then |
| it causes an exception to immediately be thrown; this is used for the |
| :meth:`throw` methods of generator objects. |
| |
| |
| .. cfunction:: int PyEval_MergeCompilerFlags(PyCompilerFlags *cf) |
| |
| This function changes the flags of the current evaluation frame, and returns |
| true on success, false on failure. |
| |
| |
| .. cvar:: int Py_eval_input |
| |
| .. index:: single: Py_CompileString() |
| |
| The start symbol from the Python grammar for isolated expressions; for use with |
| :cfunc:`Py_CompileString`. |
| |
| |