Notes/ProgrammingInPython

edit
revisions

what's new
search
help

kiwi


Programming in Python

This is a small page where I collect information about various topics I investigated while developing my projects. So far, Python is my preferred language because of its simplicity and flexibility. I know that it lacks some interesting features, but it is evolving well and consistently.

New-style classes

Python 2.2.2 eventually brought classes for all primitive types, and a new way of writing classes. This document introduces you to what has changed.

Roughly, the improvements are the following:

  • You can subclass any primitive type (like dict)
  • You have a new base class (called object)
  • You can specify how attributes are accessed and mutated (respectively with __setattr__ and __getattribute__)

There also other stuff such as a new super keyword, which semantics are somewhat different from what Java developers are used to.

I don't really know if you should convert your project from old-style classes to new-style. Judging from the new features (defining accessors, plus the new super keyword), when you are doing mostly single inheritance and have already written accessors, it does not seem really interesting.

However, changing from to new-style can be made relatively easy. Suppose that you have this:

 class A:
   ...

 class B(A):
   ...

You would simply have to do this:

 class A(object):
  ...

 class B(A):

Basically, you just have to make your root classes extend the object class. It's then up to you to decide when to use the new functionalities brought by the new style classes.

Persistence

http://xmlobject.base-art.net/doc.html http://www.orbtech.com/wiki/PyPerSyst http://blog.colorstudy.com/ianb/weblog/2004/05/26.html#P108 http://whytheluckystiff.net/syck/ .....

last modified on September 27, 2005, at 03:35 PM

© type-z.org and its contributing authors, 2001-2004.
Content is licensed under a Creative Commons License.