[Python-Dev] Re: Writing a mutable object problem with __setattr__

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):

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.