Skip to content

Triangle Zope and Python Users Group

Sections
Personal tools
You are here: Home » Boot Camps » Members » dhandy's Home » New-Style Classes Practical Overview

New-Style Classes Practical Overview

Document Actions
A practical overview of the benefits of Python's "new-style" classes, available since Python 2.2, presented via documented, self-checking sample modules.

At our TriZPUG meeting on March 23, 2005, I presented an overview of the main benefits of "new-style" classes that were introduced in Python 2.2.

It is easy to keep on using the "old-style" classes, but it helps for Python programmers to become aware of the new features available to them.

What is so great about new-style classes? From my point of view, the most practical benefits are:

  1. properties
  2. super()
  3. descriptors
  4. static and class methods

The comments and docstrings in each of these sample modules describe a feature of new-style classes. Put all of the module files in the same directory. Run a module, and it will step through the "interactive session" in the module's docstrings. Press Enter until the the module finishes running. Because these modules use advanced doctest features and also descriptors, Python 2.4 is required.

Module Description
demotest.py Extract Python interactive sessions from docstrings and run them in "demo-mode". This module is imported by all the other modules.
newclass0.py Intro, syntax of new-style classes
newclass1.py properties
newclass2.py super()
newclass3.py descriptors
newclass4.py static and class methods
Caktus Django Bootcamp
Penn State Mini-PyCamp 2012
Plone Symposium East 2012
11th Annual Python in Science Conference
PloneCon 2012
Upcoming Events
Penn State Mini-PyCamp 2012
Smeal College of Business, Penn State University, State College, PA,
2012-05-19
TriZPUG May 2012 Meeting: The Talk You Present
Room 1226, Engineering Building II, Centennial Campus, NCSU, Raleigh, NC,
2012-05-24
Django Fundamentals Bootcamp
Caktus Consulting Group, 209 Lloyd St., Carrboro, NC,
2012-06-09
« May 2012 »
Su Mo Tu We Th Fr Sa
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31    
2012-05-02
18:00-21:00 Project Night for May 2, 2012
2012-05-19
08:30 - Penn State Mini-PyCamp 2012
2012-05-20
Penn State Mini-PyCamp 2012
2012-05-21
Penn State Mini-PyCamp 2012 - 17:00
2012-05-24
19:00-21:00 TriZPUG May 2012 Meeting: The Talk You Present
 
 

This site conforms to the following standards: