5.2 Beyond Very High Level Embedding: An overview
The high level interface gives you the ability to execute arbitrary pieces of Python code
from your application, but exchanging data values is quite cumbersome to say the least. If you
want that, you should use lower level calls. At the cost of having to write more C code, you
can achieve almost anything.
It should be noted that extending Python and embedding Python is quite the same activity,
despite the different intent. Most topics discussed in the previous chapters are still valid.
To show this, consider what the extension code from Python to C really does:
- Convert data values from Python to C,
- Perform a function call to a C routine using the converted values, and
- Convert the data values from the call from C to Python.
When embedding Python, the interface code does:
- Convert data values from C to Python,
- Perform a function call to a Python interface routine using the converted values, and
- Convert the data values from the call from Python to C.
As you can see, the data conversion steps are simply swapped to accomodate the different
direction of the cross-language transfer. The only difference is the routine that you call
between both data conversions. When extending, you call a C routine, when embedding, you call
a Python routine.
This chapter will not discuss how to convert data from Python to C and vice versa. Also,
proper use of references and dealing with errors is assumed to be understood. Since these
aspects do not differ from extending the interpreter, you can refer to earlier chapters for
the required information.