Creating Subclassable Objects??

Gustavo Cordova gcordova at hebmex.com
Wed Jul 3 15:27:57 EDT 2002


> 
> I've been trying to 'update' some extension objects for my 
> python modules. I couldn't find any documentation on this,
> so I've been trying to follow along from the other object
> sources inside python.
> 
> At this point you are able to subclass the objects, the 
> problem is they just don't work. If my new class has an 
> __init__ method, it seems i cannot properly instance the
> objects (since it needs some args). If i don't have 
> an __init__ method, i can instance the new class, but none
> of the new methods i add to it work (AttributeError).
> 
> Anywhere I can look to get all the steps in place?
> 

Well, "a little bit of source-code help's the messages go down"
like the flying lady (Mary Poppins) said.

Without code, we can't know what you mean.

You *could* do some things like, say, you wanna add this
method to your functions:

>>> def SomeMethod(self, one, two, three): print one, two, three, id(self)

(hey, it's just an example).

So, you could do:

self.__class__.MethodName = SomeMethod

and presto, "self" has access to a new method called "MethodName",
which references the function "SomeMethod".

You could also create a new bound method, with:

import new
self.MethodName = new.instancemethod(SomeMethod, self, self.__class__)


and presto, you have a new bound method.

Good luck.

-gustavo





More information about the Python-list mailing list