| 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
| 2 | <html> |
| 3 | <head> |
| 4 | <link rel="STYLESHEET" href="ext.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="ext.html" title='Extending and Embedding the Python Interpreter' /> |
| 8 | <link rel='contents' href='contents.html' title="Contents" /> |
| 9 | <link rel='last' href='about.html' title='About this document...' /> |
| 10 | <link rel='help' href='about.html' title='About this document...' /> |
| 11 | <link rel="next" href="pure-embedding.html" /> |
| 12 | <link rel="prev" href="high-level-embedding.html" /> |
| 13 | <link rel="parent" href="embedding.html" /> |
| 14 | <link rel="next" href="pure-embedding.html" /> |
| 15 | <meta name='aesop' content='information' /> |
| 16 | <title>5.2 Beyond Very High Level Embedding: An overview </title> |
| 17 | </head> |
| 18 | <body> |
| 19 | <DIV CLASS="navigation"> |
| 20 | <div id='top-navigation-panel' xml:id='top-navigation-panel'> |
| 21 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> |
| 22 | <tr> |
| 23 | <td class='online-navigation'><a rel="prev" title="5.1 Very High Level" |
| 24 | href="high-level-embedding.html"><img src='../icons/previous.png' |
| 25 | border='0' height='32' alt='Previous Page' width='32' /></A></td> |
| 26 | <td class='online-navigation'><a rel="parent" title="5. Embedding Python in" |
| 27 | href="embedding.html"><img src='../icons/up.png' |
| 28 | border='0' height='32' alt='Up One Level' width='32' /></A></td> |
| 29 | <td class='online-navigation'><a rel="next" title="5.3 Pure Embedding" |
| 30 | href="pure-embedding.html"><img src='../icons/next.png' |
| 31 | border='0' height='32' alt='Next Page' width='32' /></A></td> |
| 32 | <td align="center" width="100%">Extending and Embedding the Python Interpreter</td> |
| 33 | <td class='online-navigation'><a rel="contents" title="Table of Contents" |
| 34 | href="contents.html"><img src='../icons/contents.png' |
| 35 | border='0' height='32' alt='Contents' width='32' /></A></td> |
| 36 | <td class='online-navigation'><img src='../icons/blank.png' |
| 37 | border='0' height='32' alt='' width='32' /></td> |
| 38 | <td class='online-navigation'><img src='../icons/blank.png' |
| 39 | border='0' height='32' alt='' width='32' /></td> |
| 40 | </tr></table> |
| 41 | <div class='online-navigation'> |
| 42 | <b class="navlabel">Previous:</b> |
| 43 | <a class="sectref" rel="prev" href="high-level-embedding.html">5.1 Very High Level</A> |
| 44 | <b class="navlabel">Up:</b> |
| 45 | <a class="sectref" rel="parent" href="embedding.html">5. Embedding Python in</A> |
| 46 | <b class="navlabel">Next:</b> |
| 47 | <a class="sectref" rel="next" href="pure-embedding.html">5.3 Pure Embedding</A> |
| 48 | </div> |
| 49 | <hr /></div> |
| 50 | </DIV> |
| 51 | <!--End of Navigation Panel--> |
| 52 | |
| 53 | <H1><A NAME="SECTION007200000000000000000"></A><A NAME="lower-level-embedding"></A> |
| 54 | <BR> |
| 55 | 5.2 Beyond Very High Level Embedding: An overview |
| 56 | |
| 57 | </H1> |
| 58 | |
| 59 | <P> |
| 60 | The high level interface gives you the ability to execute |
| 61 | arbitrary pieces of Python code from your application, but |
| 62 | exchanging data values is quite cumbersome to say the least. If |
| 63 | you want that, you should use lower level calls. At the cost of |
| 64 | having to write more C code, you can achieve almost anything. |
| 65 | |
| 66 | <P> |
| 67 | It should be noted that extending Python and embedding Python |
| 68 | is quite the same activity, despite the different intent. Most |
| 69 | topics discussed in the previous chapters are still valid. To |
| 70 | show this, consider what the extension code from Python to C |
| 71 | really does: |
| 72 | |
| 73 | <P> |
| 74 | |
| 75 | <OL> |
| 76 | <LI>Convert data values from Python to C, |
| 77 | </LI> |
| 78 | <LI>Perform a function call to a C routine using the |
| 79 | converted values, and |
| 80 | </LI> |
| 81 | <LI>Convert the data values from the call from C to Python. |
| 82 | </LI> |
| 83 | </OL> |
| 84 | |
| 85 | <P> |
| 86 | When embedding Python, the interface code does: |
| 87 | |
| 88 | <P> |
| 89 | |
| 90 | <OL> |
| 91 | <LI>Convert data values from C to Python, |
| 92 | </LI> |
| 93 | <LI>Perform a function call to a Python interface routine |
| 94 | using the converted values, and |
| 95 | </LI> |
| 96 | <LI>Convert the data values from the call from Python to C. |
| 97 | </LI> |
| 98 | </OL> |
| 99 | |
| 100 | <P> |
| 101 | As you can see, the data conversion steps are simply swapped to |
| 102 | accommodate the different direction of the cross-language transfer. |
| 103 | The only difference is the routine that you call between both |
| 104 | data conversions. When extending, you call a C routine, when |
| 105 | embedding, you call a Python routine. |
| 106 | |
| 107 | <P> |
| 108 | This chapter will not discuss how to convert data from Python |
| 109 | to C and vice versa. Also, proper use of references and dealing |
| 110 | with errors is assumed to be understood. Since these aspects do not |
| 111 | differ from extending the interpreter, you can refer to earlier |
| 112 | chapters for the required information. |
| 113 | |
| 114 | <P> |
| 115 | |
| 116 | <DIV CLASS="navigation"> |
| 117 | <div class='online-navigation'> |
| 118 | <p></p><hr /> |
| 119 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> |
| 120 | <tr> |
| 121 | <td class='online-navigation'><a rel="prev" title="5.1 Very High Level" |
| 122 | href="high-level-embedding.html"><img src='../icons/previous.png' |
| 123 | border='0' height='32' alt='Previous Page' width='32' /></A></td> |
| 124 | <td class='online-navigation'><a rel="parent" title="5. Embedding Python in" |
| 125 | href="embedding.html"><img src='../icons/up.png' |
| 126 | border='0' height='32' alt='Up One Level' width='32' /></A></td> |
| 127 | <td class='online-navigation'><a rel="next" title="5.3 Pure Embedding" |
| 128 | href="pure-embedding.html"><img src='../icons/next.png' |
| 129 | border='0' height='32' alt='Next Page' width='32' /></A></td> |
| 130 | <td align="center" width="100%">Extending and Embedding the Python Interpreter</td> |
| 131 | <td class='online-navigation'><a rel="contents" title="Table of Contents" |
| 132 | href="contents.html"><img src='../icons/contents.png' |
| 133 | border='0' height='32' alt='Contents' width='32' /></A></td> |
| 134 | <td class='online-navigation'><img src='../icons/blank.png' |
| 135 | border='0' height='32' alt='' width='32' /></td> |
| 136 | <td class='online-navigation'><img src='../icons/blank.png' |
| 137 | border='0' height='32' alt='' width='32' /></td> |
| 138 | </tr></table> |
| 139 | <div class='online-navigation'> |
| 140 | <b class="navlabel">Previous:</b> |
| 141 | <a class="sectref" rel="prev" href="high-level-embedding.html">5.1 Very High Level</A> |
| 142 | <b class="navlabel">Up:</b> |
| 143 | <a class="sectref" rel="parent" href="embedding.html">5. Embedding Python in</A> |
| 144 | <b class="navlabel">Next:</b> |
| 145 | <a class="sectref" rel="next" href="pure-embedding.html">5.3 Pure Embedding</A> |
| 146 | </div> |
| 147 | </div> |
| 148 | <hr /> |
| 149 | <span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span> |
| 150 | </DIV> |
| 151 | <!--End of Navigation Panel--> |
| 152 | <ADDRESS> |
| 153 | See <i><a href="about.html">About this document...</a></i> for information on suggesting changes. |
| 154 | </ADDRESS> |
| 155 | </BODY> |
| 156 | </HTML> |