Calling a derived class's constructor from a parent method

Dave Angel davea at davea.name
Wed Jan 14 19:41:51 CET 2015


On 01/14/2015 01:10 PM, jason wrote:
> On Wednesday, January 14, 2015 at 12:05:55 PM UTC-5, Mark Lawrence wrote:
>
>> I'm confused, can you please explain what you're trying to achieve
>> rather than how you're trying to achieve it and I'm sure that others
>> will give better answers than I can :)
>>
>
> Good call. Coming up with a minimal example make things pretty far out of context.
>
> The base class represents a generic function (in formal logic) with some name and a list of parameters. The derived class is some sort of specialization of that generic class (like associative functions, etc).
>
> It is desirable to do certain things to these functions, like perform substitution or canonization, that can be implemented in the basic class but which I'd like to return as a copy rather than modify the class. Thus, the base class needs to know which derived class (if any) to create.
>
> The burden is indeed on me to keep the signature of the init() for each of these the same.
>

If there are additional parameters possible, you might be able to use 
*args, **vargs to pass them through the call.

-- 
DaveA



More information about the Python-list mailing list