lots of similar classes?

Roberto Cavada cavada at irst.itc.it
Mon Jan 20 16:09:32 CET 2003

boncelet wrote:
> class Super:
>   def __init__(self,name,lots_of_other_arguments):

> class A(Super):
>   def __init__(self,name='a',lots_of_other_arguments):
>     Super.__init__(self,name,lots_of_other_arguments)
> My problem is rewriting the "lot_of_other_arguments" over and over
> again seems wasteful, error-prone, and fragile. 

mmm, see at the apply function, which you can use to call 
Super.__init__ by using a list of values to be assigned to its 
arguments. (The first element of the list must be 'self'.)
This requires that calling methods receive a list of "actual 
parameters" that implicilty respect the formal parameters order in the 
called method.

In another possible scenario, you can define a metaclass in order to 
automatically connect  formal and actual parameters. Connection could 
be performed via some syntactic rule you define.

Roberto Cavada
ITC-irst Institute for Scientific and Technological Research
Automated Reasoning Systems - Formal Methods Group
Via Sommarive, 18 - 38050 Povo (TN) - Italy
Tel: +39 0461 314 321   Fax: +39 0461 302 040
cavada at irst.itc.it  http://sra.itc.it/people/cavada/

More information about the Python-list mailing list