Changing the class of an instance

Richard Tobin richard at cogsci.ed.ac.uk
Fri Jul 14 14:09:08 EDT 2000


In article <8knhql$lpi$1 at nnrp1.deja.com>,  <david_ullrich at my-deja.com> wrote:
>   It's explicitly provided in Python as well.

No, that's just the point - it's not explicitly provided; instead the
implementation is exposed.  You can assign to the __class__ slot, you
can initialise any new slots, and delete any that the new class
doesn't have.  But does anything say "yes, this is all you need to do,
and it will work in all implementations"?  Apparently not.

>   Changing the methods of the instance also counts as
>a sneaky don't-do-that.

I thought you'd say that :-)

> Whatever it is you're trying to
>do there's a way to do it in legitimate Python without
>this sort of thing.

Ok, I trying to directly model a rather abstract specification - the
XML Infoset - as Python objects.  I then want to to perform the action
of XML Schema validation on this modelled infoset, which is defined to
add various properties to the infoset.  Various methods need to be
changed to take account of the new properties.  It is thus natural for
the class of the objects after validation to be a subclass of what
they were before.

Now obviously it can be done in many ways as a programming task, and
others might be better in engineering terms.  One might produce a new
infoset containing objects from the subclasses.  But to directly model
the specification of the validation process, changing the classes, or
adding slots and changing methods, seems the natural way.

-- Richard
-- 
Spam filter: to mail me from a .com/.net site, put my surname in the headers.

"The Internet is really just a series of bottlenecks joined by high
speed networks." - Sam Wilson



More information about the Python-list mailing list