Changing the class of an instance

david_ullrich at my-deja.com david_ullrich at my-deja.com
Mon Jul 17 11:41:01 EDT 2000


In article <8kt2qd$22i7$1 at pc-news.cogsci.ed.ac.uk>,
  richard at cogsci.ed.ac.uk (Richard Tobin) wrote:
> In article <8kq8kc$guk$1 at nnrp1.deja.com>,  <david_ullrich at my-deja.com>
wrote:
>
> >    So it's something like the value of infoset.__class__
> >changes when you call infoset.validate(schema)?
>
> Very like that - it's changing the class of some objects in the
> infoset, not the infoset itself.
>
> >but I really don't see the point
> >to changing the class of the object instead of just constructing
> >a new object.
>
> None, except to directly model the XML Schema specification which
> talks in terms of adding properties to info items in an existing
> infoset.

     Well asking why you wanted to directly model that would
be counterproductive... Even if you want to do that I don't
see the need to do anything underhanded to accomplish it.

     I actually did recently design a gizmo that was supposed
to add functionality to itself based on what it found in a
quasi-xml file. I started by adding attributes and methods
and things, but I just couldn't stand it - this meant that
I couldn't use tag names that conflicted with attribute names
in the base class (worse, it meant that revisions in the
base class would render some previously valid qml files
invlaid). I changed it to a system using __getitem__ and
__setitem__ (where they use a certain dictionary, and that
dictionary is what gets modified when the file is read.)
I sleep much better now that I can use _anything_ for a tag
name.

> > Like you pass a WellFormedInfoset to something
> >or call some method of one and get back an instance of a
> >subclass of ValidInfoset.
>
> Some other XML transformations (eg style-sheet application) are
> defined as infoset->infoset functions in that way, but this one isn't.
>
> Sometimes the aim of a program isn't (or isn't just) to calculate a
> result reliably, but to do it in a particular way to illustrate and
> explore an algorithm.

    Surely. But here we're talking about how to _implement_ an
algorithm, seems to me - an implementation that's easily seen
to be correct seems better than one where you can't tell what
anything means.

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


Sent via Deja.com http://www.deja.com/
Before you buy.



More information about the Python-list mailing list