Converting an instance to a subclass?

Tom Bridgman bridgman at
Fri Feb 16 19:49:26 CET 2001

Here's my problem (and we're currently still at Python v1.5.2 on IRIX,
if that matters).

I've defined a set of classes for manipulating some data, say class A.  

class A:
    def __init__(self,a,b,c)

and I have a number of methods that return me instances or lists of
instances of this class.  These are part of my general library of
classes for this project.

However, I need to write a utility which will define methods that are
only needed by the utility.  I really don't want these methods to be
'permanent' members of the class so I define them in a subclass as part
of the utility.

Class B(A):
   def Cleanup(self,x,y,z):

Is there a way I can cast the instances of class A into instances of
class B so I can use the additional methods?  I can't find anything
about it in "Programming Python" but then I'm not quite sure where to
look either.

For some reason I suspect I will be embarassed when I find out how
simple this might be. :^)

Dr. William T."Tom" Bridgman           Scientific Visualization Studio
Global Science & Technology, Inc.      NASA/Goddard Space Flight Center
Email: bridgman at    Code 935
Phone: 301-286-1346                    Greenbelt, MD 20771
FAX:   TBD                   

More information about the Python-list mailing list