#
2. Defining New Types

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.

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.

Note: 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.

Subsections

- 2.1 The Basics
  - 2.1.1 Adding data and methods to the Basic example
  - 2.1.2 Providing finer control over data attributes
  - 2.1.3 Supporting cyclic garbage collection
- 2.2 Type Methods
  - 2.2.1 Finalization and De-allocation
  - 2.2.2 Object Presentation
  - 2.2.3 Attribute Management
    - 2.2.3.1 Generic Attribute Management
    - 2.2.3.2 Type-specific Attribute Management
  - 2.2.4 Object Comparison
  - 2.2.5 Abstract Protocol Support
  - 2.2.6 More Suggestions