Converting an instance to a subclass?

Tom Bridgman bridgman at wyeth.gsfc.nasa.gov
Wed Feb 21 15:06:15 CET 2001


Terry et al.,

This is a really slick trick and looks like it does what I need.

Thanks to all who suggested it.  I was right.  I was *really* simple. 

Tom

Terry Reedy wrote:
> 
> > Is there a way I can cast the instances of class A into instances of
> > class B so I can use the additional methods
> 
> Is this what you want (with 1.5.2)?
> 
> >>> class a: pass
> >>> class b(a): pass
> >>> i = a()
> >>> i.__class__
> <class __main__.a at 7934f0>
> >>> i.__class__ = b
> >>> i.__class__
> <class __main__.b at 7932b0>
> 
> > I can't find anything  about it in "Programming Python"
> 
> I believe that __class__ became writeable after that was written -- or it
> may have been too esoteric (and dangerous) to include.
> 
> Terry J. Reedy

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



More information about the Python-list mailing list