Lines Matching refs:Python
7 Embedding Python in Another Application
10 The previous chapters discussed how to extend Python, that is, how to extend the
11 functionality of Python by attaching a library of C functions to it. It is also
13 embedding Python in it. Embedding provides your application with the ability to
14 implement some of the functionality of your application in Python rather than C
16 to tailor the application to their needs by writing some scripts in Python. You
17 can also use it yourself if some of the functionality can be written in Python
20 Embedding Python is similar to extending it, but not quite. The difference is
21 that when you extend Python, the main program of the application is still the
22 Python interpreter, while if you embed Python, the main program may have nothing
23 to do with Python --- instead, some parts of the application occasionally call
24 the Python interpreter to run some Python code.
26 So if you are embedding Python, you are providing your own main program. One of
27 the things this main program has to do is initialize the Python interpreter. At
29 optional calls to pass command line arguments to Python. Then later you can
33 containing Python statements to :c:func:`PyRun_SimpleString`, or you can pass a
36 described in the previous chapters to construct and use Python objects.
42 The details of Python's C interface are given in this manual. A great deal of
51 The simplest form of embedding Python is the use of the very high level
52 interface. This interface is intended to execute a Python script without needing
57 #include <Python.h>
79 :c:func:`Py_Initialize` to inform the interpreter about paths to Python run-time
80 libraries. Next, the Python interpreter is initialized with
81 :c:func:`Py_Initialize`, followed by the execution of a hard-coded Python script
84 you may want to get the Python script from another source, perhaps a text-editor
85 routine, a file, or a database. Getting the Python code from a file can better
96 Python code from your application, but exchanging data values is quite
100 It should be noted that extending Python and embedding Python is quite the same
103 Python to C really does:
105 #. Convert data values from Python to C,
109 #. Convert the data values from the call from C to Python.
111 When embedding Python, the interface code does:
113 #. Convert data values from C to Python,
115 #. Perform a function call to a Python interface routine using the converted
118 #. Convert the data values from the call from Python to C.
123 C routine, when embedding, you call a Python routine.
125 This chapter will not discuss how to convert data from Python to C and vice
136 The first program aims to execute a function in a Python script. Like in the
137 section about the very high level interface, the Python interpreter does not
141 The code to run a function defined in a Python script is:
146 This code loads a Python script using ``argv[1]``, and calls the function named
149 the finished executable :program:`call`), and use it to execute a Python
170 for data conversion between Python and C, and for error reporting. The
171 interesting part with respect to embedding Python starts with ::
179 :c:func:`PyImport_Import`. This routine needs a Python string as its argument,
194 proceeds by constructing a tuple of arguments as normal. The call to the Python
206 Extending Embedded Python
209 Until now, the embedded Python interpreter had no access to functionality from
210 the application itself. The Python API allows this by extending the embedded
213 forget for a while that the application starts the Python interpreter. Instead,
215 that gives Python access to those routines, just like you would write a normal
216 Python extension. For example::
253 :func:`emb.numargs` function accessible to the embedded Python interpreter.
254 With these extensions, the Python script can do things like
262 Python.
270 Embedding Python in C++
273 It is also possible to embed Python in a C++ program; precisely how this is done
276 program. There is no need to recompile Python itself using C++.
285 compiler (and linker) in order to embed the Python interpreter into your
286 application, particularly because Python needs to load library modules
313 To avoid confusion between several Python installations (and especially
314 between the system Python and your own compiled Python), it is recommended
321 examine Python's :file:`Makefile` (use :func:`sysconfig.get_makefile_filename`