Type casting a base class to a derived one?

Neil Cerutti horpner at yahoo.com
Thu Jan 11 09:01:48 EST 2007


On 2007-01-11, Frederic Rentsch <anthra.norell at vtxmail.ch> wrote:
> If I derive a class from another one because I need a few extra
> features, is there a way to promote the base class to the
> derived one without having to make copies of all attributes?
>
> class Derived (Base):
>    def __init__ (self, base_object):
>       # ( copy all attributes )
>       ...
>
> This looks expensive. Moreover __init__ () may not be available
> if it needs to to something else.
>
> Thanks for suggestions

How does it make sense to cast a base to a derived in your
application?

-- 
Neil Cerutti
I'm traveling to all 51 states to see who can stop 85. --Chad Johnson



More information about the Python-list mailing list