Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / amd64 / html / python / ext / defining-new-types.html
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<link rel="STYLESHEET" href="ext.css" type='text/css' />
<link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" />
<link rel='start' href='../index.html' title='Python Documentation Index' />
<link rel="first" href="ext.html" title='Extending and Embedding the Python Interpreter' />
<link rel='contents' href='contents.html' title="Contents" />
<link rel='last' href='about.html' title='About this document...' />
<link rel='help' href='about.html' title='About this document...' />
<link rel="next" href="building.html" />
<link rel="prev" href="intro.html" />
<link rel="parent" href="ext.html" />
<link rel="next" href="dnt-basics.html" />
<meta name='aesop' content='information' />
<title>2. Defining New Types
</title>
</head>
<body>
<DIV CLASS="navigation">
<div id='top-navigation-panel' xml:id='top-navigation-panel'>
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="1.12 Providing a C"
href="using-cobjects.html"><img src='../icons/previous.png'
border='0' height='32' alt='Previous Page' width='32' /></A></td>
<td class='online-navigation'><a rel="parent" title="Extending and Embedding the"
href="ext.html"><img src='../icons/up.png'
border='0' height='32' alt='Up One Level' width='32' /></A></td>
<td class='online-navigation'><a rel="next" title="2.1 The Basics"
href="dnt-basics.html"><img src='../icons/next.png'
border='0' height='32' alt='Next Page' width='32' /></A></td>
<td align="center" width="100%">Extending and Embedding the Python Interpreter</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
href="contents.html"><img src='../icons/contents.png'
border='0' height='32' alt='Contents' width='32' /></A></td>
<td class='online-navigation'><img src='../icons/blank.png'
border='0' height='32' alt='' width='32' /></td>
<td class='online-navigation'><img src='../icons/blank.png'
border='0' height='32' alt='' width='32' /></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="using-cobjects.html">1.12 Providing a C</A>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="ext.html">Extending and Embedding the</A>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="dnt-basics.html">2.1 The Basics</A>
</div>
<hr /></div>
</DIV>
<!--End of Navigation Panel-->
<H1><A NAME="SECTION004000000000000000000"></A><A NAME="defining-new-types"></A>
<BR>
2. Defining New Types
</H1>
<P>
As mentioned in the last chapter, Python allows the writer of an
extension module to define new types that can be manipulated from
Python code, much like strings and lists in core Python.
<P>
This is not hard; the code for all extension types follows a pattern,
but there are some details that you need to understand before you can
get started.
<P>
<div class="note"><b class="label">Note:</b>
The way new types are defined changed dramatically (and for the
better) in Python 2.2. This document documents how to define new
types for Python 2.2 and later. If you need to support older
versions of Python, you will need to refer to older versions of this
documentation.
</div>
<P>
<p><br /></p><hr class='online-navigation' />
<div class='online-navigation'>
<!--Table of Child-Links-->
<A NAME="CHILD_LINKS"><STRONG>Subsections</STRONG></a>
<UL CLASS="ChildLinks">
<LI><A href="dnt-basics.html">2.1 The Basics</a>
<UL>
<LI><A href="node22.html">2.1.1 Adding data and methods to the Basic example</a>
<LI><A href="node23.html">2.1.2 Providing finer control over data attributes</a>
<LI><A href="node24.html">2.1.3 Supporting cyclic garbage collection</a>
</ul>
<LI><A href="dnt-type-methods.html">2.2 Type Methods</a>
<UL>
<LI><A href="node26.html">2.2.1 Finalization and De-allocation</a>
<LI><A href="node27.html">2.2.2 Object Presentation</a>
<LI><A href="node28.html">2.2.3 Attribute Management</a>
<UL>
<LI><A href="node29.html">2.2.3.1 Generic Attribute Management</a>
<LI><A href="node30.html">2.2.3.2 Type-specific Attribute Management</a>
</ul>
<LI><A href="node31.html">2.2.4 Object Comparison</a>
<LI><A href="node32.html">2.2.5 Abstract Protocol Support</a>
<LI><A href="node33.html">2.2.6 More Suggestions</a>
</ul></ul>
<!--End of Table of Child-Links-->
</div>
<DIV CLASS="navigation">
<div class='online-navigation'>
<p></p><hr />
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="1.12 Providing a C"
href="using-cobjects.html"><img src='../icons/previous.png'
border='0' height='32' alt='Previous Page' width='32' /></A></td>
<td class='online-navigation'><a rel="parent" title="Extending and Embedding the"
href="ext.html"><img src='../icons/up.png'
border='0' height='32' alt='Up One Level' width='32' /></A></td>
<td class='online-navigation'><a rel="next" title="2.1 The Basics"
href="dnt-basics.html"><img src='../icons/next.png'
border='0' height='32' alt='Next Page' width='32' /></A></td>
<td align="center" width="100%">Extending and Embedding the Python Interpreter</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
href="contents.html"><img src='../icons/contents.png'
border='0' height='32' alt='Contents' width='32' /></A></td>
<td class='online-navigation'><img src='../icons/blank.png'
border='0' height='32' alt='' width='32' /></td>
<td class='online-navigation'><img src='../icons/blank.png'
border='0' height='32' alt='' width='32' /></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="using-cobjects.html">1.12 Providing a C</A>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="ext.html">Extending and Embedding the</A>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="dnt-basics.html">2.1 The Basics</A>
</div>
</div>
<hr />
<span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span>
</DIV>
<!--End of Navigation Panel-->
<ADDRESS>
See <i><a href="about.html">About this document...</a></i> for information on suggesting changes.
</ADDRESS>
</BODY>
</HTML>