Downcast (I know it sounds silly, but ...)

Erik Max Francis max at alcyone.com
Fri Jan 3 02:21:08 EST 2003


Rocco Rossi wrote:

> I was wondering if it is possible in Python to do something analogous
> to
> downcasting in a statically typed language like C++. I mean is it
> possible
> to take an instance of a base class and magically transform it into an
> instance of some derived class eventually fixing things (like the
> missing
> attribute data)?

Since Python has neither casts nor pointers (downcasting is done via
pointers), it's hard to tell precisely what you mean with respect to
Python.  Perhaps if you back up a step and tell us what you are trying
to do?

Certainly with Python you can do all sorts of naughty tricks, such as
manually changing the instance of a class via setting its __class__
attribute.  Whether or not that's really what you want depends on what
you're really after.

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/  \ We grow in time to trust the future for our answers.
\__/ Ruth Benedict
    Physics reference / http://www.alcyone.com/max/reference/physics/
 A physics reference.




More information about the Python-list mailing list