python constructor overloading

Greg Copeland gtcopeland at EarthLink.Net
Thu Dec 16 20:22:19 EST 1999


Okay, I have two classed in a container object.  I'd like to be able to
pass the container to both of the contained objects so that they can
call some methods that exist in the container.  Both objects are derived
from objects in another library.  So, I don't want to have to change the
other objects (as that would be anti-OO and anti-reuse, IMOHO).  At any
rate, my first thought was that I would overload the constructor of my
newly derived objects.  The problem is, I'm not sure how to do this.  I
looke in the FAQ, needless to say, those solutions suck.  As it stands,
it doesn't really look like you can overload constructors.  The end
result that I'm looking for is something like this:

# This is from another library
class base

# This is mine
class derived( base ):
	def __init__( self, caller, arg1, arg2, arg3 ):
		self.caller = caller
		base.__init__( arg1, arg2, arg3 )

As you can see, I still want the base class' constructor, as I'm really
attempting to extend the functionality in the derived class.  Of course,
it would be dandy if there is something that will give me the caller's
reference!  I realize that there are probably other ways to do this, but
this seems like the right direction (more C++'ish - maybe that's the
problem).

Please excuse the ignorance of the python newbie!

Thanks in advanced,
	Greg






More information about the Python-list mailing list