[Python-Dev] Re: Writing a mutable object problem with setattr (original) (raw)

Jeremy Hylton jeremy@zope.com
25 Feb 2003 12:52:27 -0500


On Tue, 2003-02-25 at 12:31, Guido van Rossum wrote:

> I've tried this, but then I was unable to create any of the > old-style classes. Is there any solution that would let me mutate > an object into both? I suspect not. Then the question is:

No, you can never switch an object from classic to new-style.

One possibility, which isn't quite the same thing, is to derive a new-style class from the classic class. You can write this with a class statement like so:

import cgi

class FormContent(cgi.FormContent, object): pass

or you can generate one manually:

type.new(type, "FormContent", (cgi.FormContent, object), {})

In either case, you will have a new-style class that inherits all of its behavior from the classic class.

Jeremy