Making classes from Metaclasses globally available

Jean-François Doyon jfdoyon at
Thu Jun 17 03:11:35 CEST 2004


Well, basically I'm looking at writing an IDE of sorts.  It should allow the
viewing editing of text files.

Catch is, said text files are structured much like XML, but they're NOT XML.

I want the application to be extensible, and not be stuck to a particular
version/schema of this file.

So the idea is, create one or more "schemas" to describe what I'm going to
be looking for and then parsing.

Because the format of said text file is structured in a very XML-like way, I
thought it'd make sense to simply
dynamically create a tree of objects, which are instances of relevant
classes.  But because of my statement above
I don't know in advance what classes there might be and so on.

So I figured I'd use something like MetaClasses to do it.  I've got the
basic schema parsing and class creation
in place already, the problem is that I want to keep the class creation and
the parsing fairly seperate.

I'm thinking the parsing functionality will be extra polated from the schema
also, but be part of the classes (The
file structure is consistent enough to allow this I think ...).

Anyways, it's not all entirely clear in my mind yet ... But that's the basic

But I just want classes created from the schema to be available  globally so
that when the classes need to interact with each
other (More precisely, one instance needs to instanciate another class and
make it an attribute of self) I don't need to pass
a list of classes or soemthing similar around everywhere.

Did that make any sense ? :)

Admitedly, I've kind of thought up a way to do it with a unique class ...
But I don't like that design as much ... The model
I describe above fits really well with the application in question.  I've
even seen something similar done in PHP with a
web interface, though it was much more restricted in it's flexibility and
capability to adapt to any kind of schema.

Metaclasses seem to open the door to greater flexibility by not having to
know ANYTHING in advance.

If you're familiar with the generateDS script, I've got something like that
in mind, but not for XML.

If anyone has a better idea on how to go about this, or knows of
tools/examples that implement this kind of scenario,
I'd love to hear about it!


"Jean-François Doyon" <jfdoyon at> wrote in message
news:Y%Pzc.26910$7H1.1042748 at
> Hello,
> I'm using MetaClasses to create classes.
> How do I make these new classes "globally" available?
> I probably just have to assign them to something magic, but I can't seem
> figure out which one.
> if I do:
> MetaClass('Klass', (), {})
> The resulting class needs to be assigned to something:
>     myclass = MetaClass('Klass', (), {})
> The problem is that I'm  looping and don't know in advance how many
> there will be.
> So right now I have something like:
> msclasses[clsname] = MapServerMetaClass(str(clsname), (),
> {'schema':list,'__init__':MapServerClassInit})
> inside a loop.
> Problem is I really don't want to have the classes stuck inside that dict.
> I want them "globally" available as if I had simply made a "class"
> declaration at the top of the file.
> Any ideas or suggestions?
> Thanks,
> J.F.

More information about the Python-list mailing list