class object access in class definition?
sholden at holdenweb.com
Thu Mar 8 04:01:26 CET 2001
"Lars Damerow" <lars at pixar.com> wrote in message
news:Pine.LNX.4.21.0103071835560.6130-100000 at zero...
> I figured that the my problem stems from when Python binds the class name
> the scope--when it encounters the "class" keyword, or when the class
> completes. It seems like it happens when the class definition completes.
> What I'm trying to do is automatically register the derived classes of a
> class at compile time, like this:
> derivedClasses = 
> class BaseClass:
> class DerivedClass(BaseClass):
> This doesn't work because DerivedClass doesn't seem to be bound at the
> the append() call. I can put the append() call in the DerivedClass's
> constructor, but that requires an instance to be created before the class
> be registered.
> If this isn't possible, it's no big deal; its goal is to avoid duplicating
> information in the code, nothing more.
Well, if you're prepared to be pragmatic about it, what's wrong with:
derivedClasses = 
Not elegant, but practical.
More information about the Python-list