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="node31.html" /> | |
12 | <link rel="prev" href="node27.html" /> | |
13 | <link rel="parent" href="dnt-type-methods.html" /> | |
14 | <link rel="next" href="node29.html" /> | |
15 | <meta name='aesop' content='information' /> | |
16 | <title>2.2.3 Attribute Management</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="2.2.2 Object Presentation" | |
24 | href="node27.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="2.2 Type Methods" | |
27 | href="dnt-type-methods.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="2.2.3.1 Generic Attribute Management" | |
30 | href="node29.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="node27.html">2.2.2 Object Presentation</A> | |
44 | <b class="navlabel">Up:</b> | |
45 | <a class="sectref" rel="parent" href="dnt-type-methods.html">2.2 Type Methods</A> | |
46 | <b class="navlabel">Next:</b> | |
47 | <a class="sectref" rel="next" href="node29.html">2.2.3.1 Generic Attribute Management</A> | |
48 | </div> | |
49 | <hr /></div> | |
50 | </DIV> | |
51 | <!--End of Navigation Panel--> | |
52 | ||
53 | <H2><A NAME="SECTION004230000000000000000"> | |
54 | 2.2.3 Attribute Management</A> | |
55 | </H2> | |
56 | ||
57 | <P> | |
58 | For every object which can support attributes, the corresponding type | |
59 | must provide the functions that control how the attributes are | |
60 | resolved. There needs to be a function which can retrieve attributes | |
61 | (if any are defined), and another to set attributes (if setting | |
62 | attributes is allowed). Removing an attribute is a special case, for | |
63 | which the new value passed to the handler is <tt class="constant">NULL</tt>. | |
64 | ||
65 | <P> | |
66 | Python supports two pairs of attribute handlers; a type that supports | |
67 | attributes only needs to implement the functions for one pair. The | |
68 | difference is that one pair takes the name of the attribute as a | |
69 | <tt class="ctype">char*</tt>, while the other accepts a <tt class="ctype">PyObject*</tt>. Each type | |
70 | can use whichever pair makes more sense for the implementation's | |
71 | convenience. | |
72 | ||
73 | <P> | |
74 | <div class="verbatim"><pre> | |
75 | getattrfunc tp_getattr; /* char * version */ | |
76 | setattrfunc tp_setattr; | |
77 | /* ... */ | |
78 | getattrofunc tp_getattrofunc; /* PyObject * version */ | |
79 | setattrofunc tp_setattrofunc; | |
80 | </pre></div> | |
81 | ||
82 | <P> | |
83 | If accessing attributes of an object is always a simple operation | |
84 | (this will be explained shortly), there are generic implementations | |
85 | which can be used to provide the <tt class="ctype">PyObject*</tt> version of the | |
86 | attribute management functions. The actual need for type-specific | |
87 | attribute handlers almost completely disappeared starting with Python | |
88 | 2.2, though there are many examples which have not been updated to use | |
89 | some of the new generic mechanism that is available. | |
90 | ||
91 | <P> | |
92 | ||
93 | <p><br /></p><hr class='online-navigation' /> | |
94 | <div class='online-navigation'> | |
95 | <!--Table of Child-Links--> | |
96 | <A NAME="CHILD_LINKS"><STRONG>Subsections</STRONG></a> | |
97 | ||
98 | <UL CLASS="ChildLinks"> | |
99 | <LI><A href="node29.html">2.2.3.1 Generic Attribute Management</a> | |
100 | <LI><A href="node30.html">2.2.3.2 Type-specific Attribute Management</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="2.2.2 Object Presentation" | |
111 | href="node27.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="2.2 Type Methods" | |
114 | href="dnt-type-methods.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="2.2.3.1 Generic Attribute Management" | |
117 | href="node29.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="node27.html">2.2.2 Object Presentation</A> | |
131 | <b class="navlabel">Up:</b> | |
132 | <a class="sectref" rel="parent" href="dnt-type-methods.html">2.2 Type Methods</A> | |
133 | <b class="navlabel">Next:</b> | |
134 | <a class="sectref" rel="next" href="node29.html">2.2.3.1 Generic Attribute Management</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> |