Commit | Line | Data |
---|---|---|
920dae64 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="prev" href="node32.html" /> | |
12 | <link rel="parent" href="dnt-type-methods.html" /> | |
13 | <link rel="next" href="building.html" /> | |
14 | <meta name='aesop' content='information' /> | |
15 | <title>2.2.6 More Suggestions</title> | |
16 | </head> | |
17 | <body> | |
18 | <DIV CLASS="navigation"> | |
19 | <div id='top-navigation-panel' xml:id='top-navigation-panel'> | |
20 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
21 | <tr> | |
22 | <td class='online-navigation'><a rel="prev" title="2.2.5 Abstract Protocol Support" | |
23 | href="node32.html"><img src='../icons/previous.png' | |
24 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
25 | <td class='online-navigation'><a rel="parent" title="2.2 Type Methods" | |
26 | href="dnt-type-methods.html"><img src='../icons/up.png' | |
27 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
28 | <td class='online-navigation'><a rel="next" title="3. Building C and" | |
29 | href="building.html"><img src='../icons/next.png' | |
30 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
31 | <td align="center" width="100%">Extending and Embedding the Python Interpreter</td> | |
32 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
33 | href="contents.html"><img src='../icons/contents.png' | |
34 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
35 | <td class='online-navigation'><img src='../icons/blank.png' | |
36 | border='0' height='32' alt='' width='32' /></td> | |
37 | <td class='online-navigation'><img src='../icons/blank.png' | |
38 | border='0' height='32' alt='' width='32' /></td> | |
39 | </tr></table> | |
40 | <div class='online-navigation'> | |
41 | <b class="navlabel">Previous:</b> | |
42 | <a class="sectref" rel="prev" href="node32.html">2.2.5 Abstract Protocol Support</A> | |
43 | <b class="navlabel">Up:</b> | |
44 | <a class="sectref" rel="parent" href="dnt-type-methods.html">2.2 Type Methods</A> | |
45 | <b class="navlabel">Next:</b> | |
46 | <a class="sectref" rel="next" href="building.html">3. Building C and</A> | |
47 | </div> | |
48 | <hr /></div> | |
49 | </DIV> | |
50 | <!--End of Navigation Panel--> | |
51 | ||
52 | <H2><A NAME="SECTION004260000000000000000"> | |
53 | 2.2.6 More Suggestions</A> | |
54 | </H2> | |
55 | ||
56 | <P> | |
57 | Remember that you can omit most of these functions, in which case you | |
58 | provide <code>0</code> as a value. There are type definitions for each of | |
59 | the functions you must provide. They are in <span class="file">object.h</span> in the | |
60 | Python include directory that comes with the source distribution of | |
61 | Python. | |
62 | ||
63 | <P> | |
64 | In order to learn how to implement any specific method for your new | |
65 | data type, do the following: Download and unpack the Python source | |
66 | distribution. Go the <span class="file">Objects</span> directory, then search the | |
67 | C source files for <code>tp_</code> plus the function you want (for | |
68 | example, <code>tp_print</code> or <code>tp_compare</code>). You will find | |
69 | examples of the function you want to implement. | |
70 | ||
71 | <P> | |
72 | When you need to verify that an object is an instance of the type | |
73 | you are implementing, use the <tt class="cfunction">PyObject_TypeCheck</tt> function. | |
74 | A sample of its use might be something like the following: | |
75 | ||
76 | <P> | |
77 | <div class="verbatim"><pre> | |
78 | if (! PyObject_TypeCheck(some_object, &MyType)) { | |
79 | PyErr_SetString(PyExc_TypeError, "arg #1 not a mything"); | |
80 | return NULL; | |
81 | } | |
82 | </pre></div> | |
83 | ||
84 | <DIV CLASS="navigation"> | |
85 | <div class='online-navigation'> | |
86 | <p></p><hr /> | |
87 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
88 | <tr> | |
89 | <td class='online-navigation'><a rel="prev" title="2.2.5 Abstract Protocol Support" | |
90 | href="node32.html"><img src='../icons/previous.png' | |
91 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
92 | <td class='online-navigation'><a rel="parent" title="2.2 Type Methods" | |
93 | href="dnt-type-methods.html"><img src='../icons/up.png' | |
94 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
95 | <td class='online-navigation'><a rel="next" title="3. Building C and" | |
96 | href="building.html"><img src='../icons/next.png' | |
97 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
98 | <td align="center" width="100%">Extending and Embedding the Python Interpreter</td> | |
99 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
100 | href="contents.html"><img src='../icons/contents.png' | |
101 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
102 | <td class='online-navigation'><img src='../icons/blank.png' | |
103 | border='0' height='32' alt='' width='32' /></td> | |
104 | <td class='online-navigation'><img src='../icons/blank.png' | |
105 | border='0' height='32' alt='' width='32' /></td> | |
106 | </tr></table> | |
107 | <div class='online-navigation'> | |
108 | <b class="navlabel">Previous:</b> | |
109 | <a class="sectref" rel="prev" href="node32.html">2.2.5 Abstract Protocol Support</A> | |
110 | <b class="navlabel">Up:</b> | |
111 | <a class="sectref" rel="parent" href="dnt-type-methods.html">2.2 Type Methods</A> | |
112 | <b class="navlabel">Next:</b> | |
113 | <a class="sectref" rel="next" href="building.html">3. Building C and</A> | |
114 | </div> | |
115 | </div> | |
116 | <hr /> | |
117 | <span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span> | |
118 | </DIV> | |
119 | <!--End of Navigation Panel--> | |
120 | <ADDRESS> | |
121 | See <i><a href="about.html">About this document...</a></i> for information on suggesting changes. | |
122 | </ADDRESS> | |
123 | </BODY> | |
124 | </HTML> |