Commit | Line | Data |
---|---|---|
86530b38 AT |
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="defining-new-types.html" /> | |
12 | <link rel="prev" href="contents.html" /> | |
13 | <link rel="parent" href="ext.html" /> | |
14 | <link rel="next" href="simpleExample.html" /> | |
15 | <meta name='aesop' content='information' /> | |
16 | <title>1. Extending Python with C or C++ </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="Contents" | |
24 | href="contents.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="Extending and Embedding the" | |
27 | href="ext.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="1.1 A Simple Example" | |
30 | href="simpleExample.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="contents.html">Contents</A> | |
44 | <b class="navlabel">Up:</b> | |
45 | <a class="sectref" rel="parent" href="ext.html">Extending and Embedding the</A> | |
46 | <b class="navlabel">Next:</b> | |
47 | <a class="sectref" rel="next" href="simpleExample.html">1.1 A Simple Example</A> | |
48 | </div> | |
49 | <hr /></div> | |
50 | </DIV> | |
51 | <!--End of Navigation Panel--> | |
52 | ||
53 | <H1><A NAME="SECTION003000000000000000000"></A><A NAME="intro"></A> | |
54 | <BR> | |
55 | 1. Extending Python with C or C++ | |
56 | </H1> | |
57 | ||
58 | <P> | |
59 | It is quite easy to add new built-in modules to Python, if you know | |
60 | how to program in C. Such <i class="dfn">extension modules</i> can do two things | |
61 | that can't be done directly in Python: they can implement new built-in | |
62 | object types, and they can call C library functions and system calls. | |
63 | ||
64 | <P> | |
65 | To support extensions, the Python API (Application Programmers | |
66 | Interface) defines a set of functions, macros and variables that | |
67 | provide access to most aspects of the Python run-time system. The | |
68 | Python API is incorporated in a C source file by including the header | |
69 | <code>"Python.h"</code>. | |
70 | ||
71 | <P> | |
72 | The compilation of an extension module depends on its intended use as | |
73 | well as on your system setup; details are given in later chapters. | |
74 | ||
75 | <P> | |
76 | ||
77 | <p><br /></p><hr class='online-navigation' /> | |
78 | <div class='online-navigation'> | |
79 | <!--Table of Child-Links--> | |
80 | <A NAME="CHILD_LINKS"><STRONG>Subsections</STRONG></a> | |
81 | ||
82 | <UL CLASS="ChildLinks"> | |
83 | <LI><A href="simpleExample.html">1.1 A Simple Example</a> | |
84 | <LI><A href="errors.html">1.2 Intermezzo: Errors and Exceptions</a> | |
85 | <LI><A href="backToExample.html">1.3 Back to the Example</a> | |
86 | <LI><A href="methodTable.html">1.4 The Module's Method Table and Initialization Function</a> | |
87 | <LI><A href="compilation.html">1.5 Compilation and Linkage</a> | |
88 | <LI><A href="callingPython.html">1.6 Calling Python Functions from C</a> | |
89 | <LI><A href="parseTuple.html">1.7 Extracting Parameters in Extension Functions</a> | |
90 | <LI><A href="parseTupleAndKeywords.html">1.8 Keyword Parameters for Extension Functions</a> | |
91 | <LI><A href="buildValue.html">1.9 Building Arbitrary Values</a> | |
92 | <LI><A href="refcounts.html">1.10 Reference Counts</a> | |
93 | <UL> | |
94 | <LI><A href="refcountsInPython.html">1.10.1 Reference Counting in Python</a> | |
95 | <LI><A href="ownershipRules.html">1.10.2 Ownership Rules</a> | |
96 | <LI><A href="thinIce.html">1.10.3 Thin Ice</a> | |
97 | <LI><A href="nullPointers.html">1.10.4 NULL Pointers</a> | |
98 | </ul> | |
99 | <LI><A href="cplusplus.html">1.11 Writing Extensions in C++</a> | |
100 | <LI><A href="using-cobjects.html">1.12 Providing a C API for an Extension Module</a> | |
101 | </ul> | |
102 | <!--End of Table of Child-Links--> | |
103 | </div> | |
104 | ||
105 | <DIV CLASS="navigation"> | |
106 | <div class='online-navigation'> | |
107 | <p></p><hr /> | |
108 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
109 | <tr> | |
110 | <td class='online-navigation'><a rel="prev" title="Contents" | |
111 | href="contents.html"><img src='../icons/previous.png' | |
112 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
113 | <td class='online-navigation'><a rel="parent" title="Extending and Embedding the" | |
114 | href="ext.html"><img src='../icons/up.png' | |
115 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
116 | <td class='online-navigation'><a rel="next" title="1.1 A Simple Example" | |
117 | href="simpleExample.html"><img src='../icons/next.png' | |
118 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
119 | <td align="center" width="100%">Extending and Embedding the Python Interpreter</td> | |
120 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
121 | href="contents.html"><img src='../icons/contents.png' | |
122 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
123 | <td class='online-navigation'><img src='../icons/blank.png' | |
124 | border='0' height='32' alt='' width='32' /></td> | |
125 | <td class='online-navigation'><img src='../icons/blank.png' | |
126 | border='0' height='32' alt='' width='32' /></td> | |
127 | </tr></table> | |
128 | <div class='online-navigation'> | |
129 | <b class="navlabel">Previous:</b> | |
130 | <a class="sectref" rel="prev" href="contents.html">Contents</A> | |
131 | <b class="navlabel">Up:</b> | |
132 | <a class="sectref" rel="parent" href="ext.html">Extending and Embedding the</A> | |
133 | <b class="navlabel">Next:</b> | |
134 | <a class="sectref" rel="next" href="simpleExample.html">1.1 A Simple Example</A> | |
135 | </div> | |
136 | </div> | |
137 | <hr /> | |
138 | <span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span> | |
139 | </DIV> | |
140 | <!--End of Navigation Panel--> | |
141 | <ADDRESS> | |
142 | See <i><a href="about.html">About this document...</a></i> for information on suggesting changes. | |
143 | </ADDRESS> | |
144 | </BODY> | |
145 | </HTML> |